From ae8a89ec25fe0bee75add95f756dc2bb1d83021b Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 22 Apr 2026 19:58:08 +0200 Subject: [PATCH] Get the UUID from the imported file or directory --- cmdline/state.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cmdline/state.c b/cmdline/state.c index 80706d8c..cf523aa7 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -671,7 +671,6 @@ void state_config(struct snapraid_state* state, const char* path, const char* co char device[PATH_MAX]; char* split_map[SPLIT_MAX + 1]; unsigned split_mac; - char* slash; uint64_t dev; int skip_access; @@ -717,16 +716,15 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* get the device of the directory containing the parity file */ pathimport(device, sizeof(device), split_map[s]); - slash = strrchr(device, '/'); - if (slash) - slash[1] = 0; - else - pathcpy(device, sizeof(device), "."); + + /* use only the dir, as the parity file may not exist yet */ + pathcut(device); + if (stat(device, &st) == 0) { dev = st.st_dev; /* read the uuid, if unsupported use an empty one */ - if (devuuid(dev, split_map[s], uuid, sizeof(uuid)) != 0) { + if (devuuid(dev, device, uuid, sizeof(uuid)) != 0) { *uuid = 0; } } else { @@ -964,7 +962,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co dev = st.st_dev; /* read the uuid, if unsupported use an empty one */ - if (devuuid(dev, dir, uuid, sizeof(uuid)) != 0) { + if (devuuid(dev, device, uuid, sizeof(uuid)) != 0) { *uuid = 0; } @@ -1065,7 +1063,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co dev = st.st_dev; /* read the uuid, if unsupported use an empty one */ - if (devuuid(dev, dir, uuid, sizeof(uuid)) != 0) { + if (devuuid(dev, device, uuid, sizeof(uuid)) != 0) { *uuid = 0; }