Skip to content

Commit

Permalink
Delete all dst subvols before rm
Browse files Browse the repository at this point in the history
Because the dst may contain readonly subvols we can remove with
rm.
  • Loading branch information
cvaroqui committed Mar 20, 2023
1 parent 9caf967 commit c86d08a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions opensvc/drivers/resource/sync/btrfs/__init__.py
Expand Up @@ -408,6 +408,15 @@ def remove_src_snap_last(self):
return []
return [subprocess.list2cmdline(cmd)]

def remove_dst(self, node):
o = self.get_btrfs(node)
p = self.dst
subvols = o.get_subvols_in_path(p)
cmd = o.subvol_delete_cmd(subvols) or []
if not cmd:
return []
return [subprocess.list2cmdline(cmd)]

def rename_src_snap_next(self):
src = self.src_next_dir()
dst = self.src_last_dir()
Expand All @@ -423,19 +432,13 @@ def rename_dst_snap_next(self, node):
]
return cmds

def remove_dst(self, subvol, node):
dst = os.path.join(self.dst, subvol["path"])
cmd = self.dst_btrfs[node].subvol_delete_cmd(dst)
if not cmd:
return []
return [subprocess.list2cmdline(cmd)]

def install_final(self, node):
head_subvol = self.subvols()[0]
src = os.path.join(self.dst_temp_dir(node), head_subvol["path"])
if protected_dir(self.dst):
raise ex.Error("%s is a protected dir. refuse to remove" % self.dst)
cmds = [
cmds = self.remove_dst(node)
cmds += [
subprocess.list2cmdline(["rm", "-rf", self.dst]),
subprocess.list2cmdline(["mv", "-v", src, self.dst]),
]
Expand Down

0 comments on commit c86d08a

Please sign in to comment.