From ee7bf6ddbca0423f7a6a799ec34136896903fd58 Mon Sep 17 00:00:00 2001 From: Papoteur Date: Thu, 1 Jan 2026 15:30:50 +0100 Subject: Fix running do_format in magiback (mga#34877 mga#34867) Restore erasing MBR when formatting in one partition Fix messages about partition, not only persistent partition. --- backend/magiback | 16 ++++++++-------- backend/raw_write.py | 46 ++++++++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 28 deletions(-) (limited to 'backend') diff --git a/backend/magiback b/backend/magiback index d67c11d..766ba81 100755 --- a/backend/magiback +++ b/backend/magiback @@ -30,10 +30,11 @@ class Isodumper(raw_write.Dumper): - - - - + + + + + @@ -103,17 +104,16 @@ class Isodumper(raw_write.Dumper): logging.debug(self.return_message) self.finished.set() - def do_format(self, target, label, key, fs_type, order): + def do_format(self, target, label, key, fs_type, order, dbus_context): self.finished.clear() - if self.writing_perm and self.writing_target == target: - self.thread = threading.Thread(target=self._do_format, args=(target, label, key, fs_type, order=order)) + if (self.writing_perm and self.writing_target == target) or check_permission('org.mageia.Magiback.Isodumper.write', dbus_context): + self.thread = threading.Thread(target=self._do_format, args=(target, label, key, fs_type, order.encode("utf-8"))) self.thread.start() logging.info("Partitioning thread started") else: self.return_message = "Partitioning: Access denied" logging.info(self.return_message) self.finished.set() - self.writing_perm = False self.writing_target = "" @property diff --git a/backend/raw_write.py b/backend/raw_write.py index 7a7ae18..9a340b0 100755 --- a/backend/raw_write.py +++ b/backend/raw_write.py @@ -198,8 +198,13 @@ class Dumper(object): return False return True - def _do_format(self, target, label, key, fs_type, order=3): - logging.debug("Start doing persistence partition") + def _do_format(self, target, label, key, fs_type, order=b"3"): + logging.debug(f"Start doing partition on {target} with label {label} in order {order}") + if order == b"1": + logging.debug("Erasing MBR") + # First erase MBR and partition table , if any + # execute(["dd", "if=/dev/zero", "of=%s" % device_path, "bs=512", "count=1"]) + self._do_write("/dev/zero", target, 512, False, 0, 0) p = Popen(["fdisk", target], stdin=PIPE, stderr=PIPE) # commands: # n : new @@ -208,7 +213,7 @@ class Dumper(object): # default first sector # default last sector # w : write and quit - outs, errs = p.communicate(input=b"n\np\n" + bytes(order) + b"\n\n\nw\n") + outs, errs = p.communicate(input=b"n\np\n" + order + b"\n\n\nw\n") working = True while working: time.sleep(0.5) @@ -223,7 +228,7 @@ class Dumper(object): if rc == 1: # the error is Re-reading the partition table failed.: Device or resource busy logging.error( - _("Error {} while doing persistent partition: {}").format( + _("Error {} while doing partition: {}").format( rc, errs.decode("utf-8") ) ) @@ -249,7 +254,7 @@ class Dumper(object): else: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while doing partition: {}" ).format(rc, errs.decode("utf-8")) logging.error(self.return_message) self.finished.set() @@ -266,7 +271,7 @@ class Dumper(object): if key == "": # example mkfs.ext4 -L mgalive-persist /dev/sdf3 self.return_message = _("Additional partition added. Formatting...") - path = target + str(order) + path = target + str(order, "utf-8") # Format partition according to the fs_type specified fs_type = fs_type.lower() if fs_type == "fat32": @@ -300,23 +305,24 @@ class Dumper(object): if rc == 0: self.return_state = True self._progress = 100 - self.return_message = _("Persistent partition done") + self.return_message = _("Partition done") else: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while doing partition: {}" ).format(rc, errs.decode("utf-8")) self.finished.set() return - logging.info("Persistent partition done") + logging.info("Partition done") if not self.udev_wait(_("formatting partition")): return else: # example cryptsetup luksFormat /dev/sdb3 - self.return_message = _("Persistent partition added. Encrypting...") - base_target = os.path.basename(target) + str(order) + self.return_message = _("Partition added. Encrypting...") + logging.debug(f"Encrypting {str(order, 'utf-8')}") + base_target = os.path.basename(target) + str(order, "utf-8") process = Popen( - ["cryptsetup", "luksFormat", "-q", target + str(order), "-d", "-"], + ["cryptsetup", "luksFormat", "-q", target + str(order, "utf-8"), "-d", "-"], stdin=PIPE, stderr=PIPE, ) @@ -334,13 +340,13 @@ class Dumper(object): if rc != 0: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while encrypting partition: {}" ).format(rc, errs.decode("utf-8")) logging.error(self.return_message) self.finished.set() return self._progress = 50 - self.return_message = _("Persistent partition encrypted. Opening...") + self.return_message = _("Partition encrypted. Opening...") # cryptsetup open /dev/sdb3 crypt_sdb3 if not self.udev_wait("creating encrypted partition"): return @@ -349,7 +355,7 @@ class Dumper(object): [ "cryptsetup", "luksOpen", - target + str(order), + target + str(order, "utf-8"), "crypt_" + base_target, "-d", "-", @@ -371,7 +377,7 @@ class Dumper(object): if rc != 0: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while doing partition: {}" ).format(rc, errs.decode("utf-8")) logging.error(self.return_message) self.finished.set() @@ -380,7 +386,7 @@ class Dumper(object): if not self.udev_wait(_("opening encrypted partition")): return self._progress = 60 - self.return_message = _("Persistent partition opened. Formatting...") + self.return_message = _("Partition opened. Formatting...") # mkfs.ext4 -L mgalive-persist /dev/mapper/crypt_sdb3 process = Popen( [ @@ -407,7 +413,7 @@ class Dumper(object): if rc != 0: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while doing partition: {}" ).format(rc, errs.decode("utf-8")) logging.error(self.return_message) self.finished.set() @@ -432,12 +438,12 @@ class Dumper(object): if rc != 0: self.return_state = False self.return_message = _( - "Error {} while doing persistent partition: {}" + "Error {} while doing partition: {}" ).format(rc, errs.decode("utf-8")) logging.error(self.return_message) else: self.return_state = True - self.return_message = _("Persistent partition done") + self.return_message = _("Partition done") logging.info(self.return_message) if not self.udev_wait(_("closing encrypted partition")): return -- cgit v1.2.1