]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hwdb: Don't generate hwdb if no hwdb files are found
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 21 Jun 2023 11:17:01 +0000 (13:17 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 22 Jun 2023 14:07:22 +0000 (16:07 +0200)
src/shared/hwdb-util.c

index 59b678c424d8548db724d2e3b60b588fe8a41c4a..12621b7f89d19fb40e7d579a30aa23add9b4d651 100644 (file)
@@ -587,6 +587,10 @@ int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool co
          * source. If true, then hwdb.bin will be created without the information. systemd-hwdb command
          * should set the argument false, and 'udevadm hwdb' command should set it true. */
 
+        hwdb_bin = path_join(root, hwdb_bin_dir ?: "/etc/udev", "hwdb.bin");
+        if (!hwdb_bin)
+                return -ENOMEM;
+
         trie = new0(struct trie, 1);
         if (!trie)
                 return -ENOMEM;
@@ -607,6 +611,18 @@ int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool co
         if (err < 0)
                 return log_error_errno(err, "Failed to enumerate hwdb files: %m");
 
+        if (strv_isempty(files)) {
+                if (unlink(hwdb_bin) < 0) {
+                        if (errno != ENOENT)
+                                return log_error_errno(errno, "Failed to remove compiled hwdb database %s: %m", hwdb_bin);
+
+                        log_info("No hwdb files found, skipping.");
+                } else
+                        log_info("No hwdb files found, compiled hwdb database %s removed.", hwdb_bin);
+
+                return 0;
+        }
+
         STRV_FOREACH(f, files) {
                 log_debug("Reading file \"%s\"", *f);
                 err = import_file(trie, *f, file_priority++, compat);
@@ -630,10 +646,6 @@ int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool co
         log_debug("strings dedup'ed: %8zu bytes (%8zu)",
                   trie->strings->dedup_len, trie->strings->dedup_count);
 
-        hwdb_bin = path_join(root, hwdb_bin_dir ?: "/etc/udev", "hwdb.bin");
-        if (!hwdb_bin)
-                return -ENOMEM;
-
         (void) mkdir_parents_label(hwdb_bin, 0755);
         err = trie_store(trie, hwdb_bin, compat);
         if (err < 0)