]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart/makefs: port over to path_extract_filename()
authorLennart Poettering <lennart@poettering.net>
Wed, 21 Dec 2022 15:50:18 +0000 (16:50 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 23 Dec 2022 14:04:19 +0000 (15:04 +0100)
src/partition/makefs.c
src/partition/repart.c

index 3f54bbb0da0a9a2a0739e0295f0f3185616705f1..2733763eb2fa43346a9530bd0a54724bb0f355ab 100644 (file)
 #include "fd-util.h"
 #include "main-func.h"
 #include "mkfs-util.h"
+#include "path-util.h"
 #include "process-util.h"
 #include "signal-util.h"
 #include "string-util.h"
 
 static int run(int argc, char *argv[]) {
-        _cleanup_free_ char *device = NULL, *fstype = NULL, *detected = NULL;
+        _cleanup_free_ char *device = NULL, *fstype = NULL, *detected = NULL, *label = NULL;
         _cleanup_close_ int lock_fd = -EBADF;
         sd_id128_t uuid;
         struct stat st;
@@ -65,7 +66,11 @@ static int run(int argc, char *argv[]) {
         if (r < 0)
                 return log_error_errno(r, "Failed to generate UUID for file system: %m");
 
-        return make_filesystem(device, fstype, basename(device), NULL, uuid, true, NULL);
+        r = path_extract_filename(device, &label);
+        if (r < 0)
+                return log_error_errno(r, "Failed to extract file name from '%s': %m", device);
+
+        return make_filesystem(device, fstype, label, NULL, uuid, true, NULL);
 }
 
 DEFINE_MAIN_FUNCTION(run);
index 71018a79cc861834e2810b531572e3f492e03cf3..6feb6ca2a1941d7fd2bde941e8106e620bfe72c4 100644 (file)
@@ -2580,10 +2580,8 @@ static int partition_hint(const Partition *p, const char *node, char **ret) {
 
         /* Tries really hard to find a suitable description for this partition */
 
-        if (p->definition_path) {
-                buf = strdup(basename(p->definition_path));
-                goto done;
-        }
+        if (p->definition_path)
+                return path_extract_filename(p->definition_path, ret);
 
         label = partition_label(p);
         if (!isempty(label)) {