Skip to content

Commit 2e135ff

Browse files
authored
Subvolume: Enhance nested subvolume deletion verification process (#467)
1 parent e202858 commit 2e135ff

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

src/Core/Subvolume.vala

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,22 @@ public class Subvolume : GLib.Object{
148148
}
149149

150150
subpath = path_combine(path, name);
151-
if (dir_exists(subpath)) { // there is a nested subvol to remove first
152-
cmd = "btrfs subvolume delete %s '%s'".printf(options, subpath);
153-
log_debug("Deleting nested subvolume in snapshot");
154-
log_debug(cmd);
155-
ret_val = exec_sync(cmd, out std_out, out std_err);
156-
if (ret_val != 0){
157-
log_error(std_err);
158-
log_error(_("Failed to delete snapshot nested subvolume") + ": '%s'".printf(path));
159-
return false;
151+
if (dir_exists(subpath)) { // possible nested subvolume present, verify before deleting
152+
int rc_show = exec_sync("btrfs subvolume show '%s'".printf(subpath), out std_out, out std_err);
153+
if (rc_show == 0) {
154+
// confirmed nested btrfs subvolume, delete it first
155+
cmd = "btrfs subvolume delete %s '%s'".printf(options, subpath);
156+
log_debug("Deleting nested subvolume in snapshot");
157+
log_debug(cmd);
158+
ret_val = exec_sync(cmd, out std_out, out std_err);
159+
if (ret_val != 0){
160+
log_error(std_err);
161+
log_error(_("Failed to delete snapshot nested subvolume") + ": '%s'".printf(subpath));
162+
return false;
163+
}
164+
} else {
165+
// path exists but is not a btrfs subvolume, skip nested removal
166+
log_debug("Nested path exists but is not a btrfs subvolume, skipping: %s".printf(subpath));
160167
}
161168
}
162169

0 commit comments

Comments
 (0)