]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: introduce device_has_db() helper function 30596/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 22 Nov 2023 04:05:26 +0000 (13:05 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 22 Dec 2023 19:45:13 +0000 (04:45 +0900)
src/libsystemd/sd-device/device-private.c
src/libsystemd/sd-device/device-private.h

index 90df3f724d8c3f15bcbe3630585c546dc792f693..cd85ec9c6297bcfa02870e029c175f36fa60886d 100644 (file)
@@ -809,6 +809,19 @@ static int device_get_db_path(sd_device *device, char **ret) {
         return 0;
 }
 
+int device_has_db(sd_device *device) {
+        _cleanup_free_ char *path = NULL;
+        int r;
+
+        assert(device);
+
+        r = device_get_db_path(device, &path);
+        if (r < 0)
+                return r;
+
+        return access(path, F_OK) >= 0;
+}
+
 int device_update_db(sd_device *device) {
         _cleanup_(unlink_and_freep) char *path = NULL, *path_tmp = NULL;
         _cleanup_fclose_ FILE *f = NULL;
index a0161e7c12a5cbce1383ca24f90590e3f7e7241c..79a0013dc71d1085aaf6e63dcda484503730bd97 100644 (file)
@@ -59,6 +59,7 @@ int device_clone_with_db(sd_device *device, sd_device **ret);
 
 int device_tag_index(sd_device *dev, sd_device *dev_old, bool add);
 bool device_should_have_db(sd_device *device);
+int device_has_db(sd_device *device);
 int device_update_db(sd_device *device);
 int device_delete_db(sd_device *device);
 int device_read_db_internal_filename(sd_device *device, const char *filename); /* For fuzzer */