aboutsummaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rwxr-xr-xbackend/magiback5
-rwxr-xr-xbackend/raw_write.py40
2 files changed, 35 insertions, 10 deletions
diff --git a/backend/magiback b/backend/magiback
index e7541c3..2ad748b 100755
--- a/backend/magiback
+++ b/backend/magiback
@@ -94,9 +94,12 @@ class Isodumper(raw_write.Dumper):
def do_persistence(self, target, label, key):
self.finished.clear()
if self.writing_perm and self.writing_target == target :
- self._do_persistence(target, label, key)
+ self.thread = threading.Thread(target=self._do_persistence, args=(target, label, key))
+ self.thread.start()
+ logging.debug("Persistence thread started")
else:
self.return_message = "Persistence: Access denied"
+ self.finished.set()
self.writing_perm = False
self.writing_target = ""
diff --git a/backend/raw_write.py b/backend/raw_write.py
index 33279d7..0bdaf81 100755
--- a/backend/raw_write.py
+++ b/backend/raw_write.py
@@ -261,10 +261,24 @@ class Dumper(object):
self.return_message = _("Error while doing persistent partition: ") + errs.decode('utf-8')
return
logging.debug("New partition created")
-
- # Wait some time to propagate the info of new partition table
- time.sleep(1.0)
+ self._progress = 33
+ # Wait for propagation of the info of new partition table
+ wait = Popen(["udevadm","settle","--timeout=15"], stderr=PIPE)
+ outs, errs = wait.communicate()
+ working=True
+ while working:
+ time.sleep(0.5)
+ wait.poll()
+ rc=wait.returncode
+ if not (rc is None):
+ wait = None
+ working= False
+ if rc != 0:
+ self.return_state = False
+ self.return_message = _("Timeout reached when creating a new partition table")
+ return
+ self._progress = 50
if key == "":
# example mkfs.ext4 -L mgalive-persist /dev/sdf3
process = Popen(['mkfs.ext4','-L', label, target+"3"],stderr=PIPE)
@@ -281,13 +295,14 @@ class Dumper(object):
working= False
if rc == 0:
self.return_state = True
+ self._progress = 100
self.return_message = _("Persistent partition done")
else:
self.return_state = False
- self.return_message = _("Error while doing persistent partition: ") + errs
+ self.return_message = _("Error while doing persistent partition: ") + errs.decode("utf-8")
+ self.finished.set()
return
logging.info("Persistent partition done")
-
else:
# example cryptsetup luksFormat /dev/sdb3
print("Crypt key provided",file=sys.stderr)
@@ -306,9 +321,11 @@ class Dumper(object):
working= False
if rc != 0:
self.return_state = False
- self.return_message = _("Error while doing persistent partition: ") + errs
+ self.return_message = _("Error while doing persistent partition: ") + errs.decode("utf-8")
logging.error(self.return_message)
+ self.finished.set()
return
+ self._progress = 75
# cryptsetup open /dev/sdb3 crypt_sdb3
process = Popen(['cryptsetup','luksOpen', target + "3", 'crypt_' + base_target ,'-d','-'],stdin=PIPE, stderr=PIPE)
@@ -325,8 +342,9 @@ class Dumper(object):
working= False
if rc != 0:
self.return_state = False
- self.return_message = _("Error while doing persistent partition: ") + errs
+ self.return_message = _("Error while doing persistent partition: ") + errs.decode("utf-8")
logging.error(self.return_message)
+ self.finished.set()
return
# mkfs.ext4 -L mgalive-persist /dev/mapper/crypt_sdb3
@@ -344,8 +362,9 @@ class Dumper(object):
working= False
if rc != 0:
self.return_state = False
- self.return_message = _("Error while doing persistent partition: ") + errs
+ self.return_message = _("Error while doing persistent partition: ") + errs.decode("utf-8")
logging.error(self.return_message)
+ self.finished.set()
return
# cryptsetup close crypt_sdb3
@@ -363,12 +382,15 @@ class Dumper(object):
working= False
if rc != 0:
self.return_state = False
- self.return_message = _("Error while doing persistent partition: ") + errs
+ self.return_message = _("Error while doing persistent partition: ") + errs.decode("utf-8")
logging.error(self.return_message)
else:
self.return_state = True
self.return_message = _("Persistent partition done")
logging.info("Persistent partition done")
+ self._progress = 100
+ self.finished.set()
+ logging.debug("Finished")
def __init__(self):