Skip to content

Commit

Permalink
fix: improve subvolume create/delete logic and add a exists_on_disk a…
Browse files Browse the repository at this point in the history
…trribute to BtrfsSubvolume
  • Loading branch information
Vilez0 committed Apr 21, 2024
1 parent 1017eca commit 6be4875
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
20 changes: 10 additions & 10 deletions live-installer/frontend/gtk_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,20 +1004,20 @@ def update_partition_menu(pid, status):

def part_remove_button_event(self,widget):
if self.selected_partition.type == _("btrfs subvolume"):
subvolume_name = self.selected_partition.name
subvolume_parent = self.selected_partition.parent
subvolume = self.selected_partition
if QuestionDialog(_("Are you sure?"),
_("subvolume {} will removed from {}.").format(subvolume_name, subvolume_parent.path)):
_("subvolume {} will removed from {}.").format(subvolume.name, subvolume.parent.path)):
model, itervar = self.builder.get_object(
"treeview_disks").get_selection().get_selected()
subvolume_parent.subvolumes.remove(self.selected_partition)
mount_point = getoutput("mktemp -d").decode("utf-8").strip()
os.system("mount -t btrfs %s %s" %
(subvolume_parent.path, mount_point))
os.system("btrfs subvolume delete %s/%s" %
(mount_point, subvolume_name))
os.system("umount --force %s" % mount_point)
subvolume.parent.subvolumes.remove(subvolume)
model.remove(itervar)
if not subvolume.exists_on_disk:
mount_point = getoutput("mktemp -d").decode("utf-8").strip()
os.system("mount -t btrfs %s %s" %
(subvolume.parent.path, mount_point))
os.system("btrfs subvolume delete %s/%s" %
(mount_point, subvolume.name))
os.system("umount --force %s" % mount_point)
return
path = self.selected_partition.path
mbr = self.selected_partition.mbr
Expand Down
2 changes: 2 additions & 0 deletions live-installer/frontend/partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def get_btrfs_partition_subvolumes(partition):
subvolume = BtrfsSubvolume()
subvolume.name = subvol.split(" path ")[1]
subvolume.parent = partition
subvolume.exists_on_disk = True
subvolumes.append(subvolume)
log("subvolume: %s" % subvolume.name)
return subvolumes
Expand Down Expand Up @@ -763,6 +764,7 @@ def __init__(self):
self.parent = None
self.partition = self
self.mount_as = ''
self.exists_on_disk = False

class PartitionDialog(object):
def __init__(self, path, mount_as, format_as, typevar, read_only=False):
Expand Down
5 changes: 4 additions & 1 deletion live-installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,12 @@ def mount_partitions(self):
if 0 == self.do_mount(partition.path, "/target", partition.type, None):
if fs == "btrfs":
log(" ------ Found btrfs filesystem")
# Create subvolumes for Btrfs
if partition.subvolumes != []:
# Create subvolumes
partition.subvolumes.sort(key = lambda x : x.name, reverse=False)
for subvolume in partition.subvolumes:
if subvolume.exists_on_disk:
continue
log(" ------ Creating btrfs subvolume {} on /target/{}".format(subvolume.name,subvolume.mount_as))
# btrfs-progs have a parameter to create subvolumes with parent directories but in a version newer(v6.5.3) than the debian 12 package(v6.2)
# you can replace this with "btrfs subvolume create -p" when next debian release(trixie) based pardus is out
Expand All @@ -432,6 +434,7 @@ def mount_partitions(self):
os.system("btrfs subvolume create /target/{}".format(subvolume.name))

os.system("umount --force /target")
# Mount subvolumes
partition.subvolumes.sort(key = lambda x : x.mount_as, reverse=False)
for subvolume in partition.subvolumes:
log(" ------ Mounting btrfs subvolume {} on /target/{}".format(subvolume.name,subvolume.mount_as))
Expand Down

0 comments on commit 6be4875

Please sign in to comment.