Allow applying snapshots

This commit is contained in:
Heliguy
2024-09-27 21:52:02 -04:00
parent 5d6b408259
commit a59ec72951
2 changed files with 22 additions and 11 deletions

View File

@@ -112,18 +112,24 @@ class SnapshotBox(Gtk.Box):
dialog.present(HostInfo.main_window)
def get_fraction(self):
loading_status = self.parent_page.parent_page.loading_status
loading_status = self.snapshot_page.snapshotting_status
loading_status.title_label.set_label(_("Applying Snapshot"))
loading_status.progress_bar.set_fraction(total / len(self.workers))
loading_status.progress_bar.set_fraction(self.worker.fraction)
if self.worker.stop:
self.snapshot_page.status_stack.set_visible_child(self.snapshot_page.split_view)
return False # Stop the timeout
else:
return True # Continue the timeout
def on_apply(self, button):
self.parent_page.parent_page.status_stack.set_visible_child(self.snapshot_page.snapshotting_view)
self.snapshot_page.status_stack.set_visible_child(self.snapshot_page.snapshotting_view)
self.worker.extract()
GLib.timeout_add(200, self.get_fraction)
def __init__(self, parent_page, folder, snapshots_path, toast_overlay, **kwargs):
super().__init__(**kwargs)
self.snapshot_page = parent_page.parent_page
self.toast_overlay = toast_overlay
self.app_id = snapshots_path.split('/')[-2].strip()
self.worker = TarWorker(

View File

@@ -49,18 +49,23 @@ class TarWorker:
def extract_thread(self, *args):
try:
if not os.path.exists(self.new_path):
os.makedirs(self.new_path) # create the new user data path if none exists
else:
subprocess.run('gio', 'trash', self.new_path) # trash the current user data, because new data will go in its place
if os.path.exists(self.new_path):
subprocess.run(['gio', 'trash', self.new_path], capture_output=True, check=True) # trash the current user data, because new data will go in its place
os.makedirs(self.new_path) # create the new user data path
self.total = int(subprocess.run(['du', '-s', self.existing_path], check=True, text=True, capture_output=True).stdout.split('\t')[0])
self.total *= 2.2 # estimate from space savings
self.process = subprocess.Popen(['tar', '--zstd', '-xvf', self.existing_path, '-C', self.new_path])
self.process = subprocess.Popen(['tar', '--zstd', '-xvf', self.existing_path, '-C', self.new_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = self.process.communicate()
if self.process.returncode != 0:
raise subprocess.CalledProcessError(self.process.returncode, self.process.args, output=stdout, stderr=stderr)
self.stop = True # tell the check timeout to stop, because we know the file is done being made
except subprocess.CalledProcessError as cpe:
print("Called Error in Extract Thread")
self.do_cancel(cpe.stderr.decode(), [self.new_path])
@@ -74,7 +79,7 @@ class TarWorker:
self.process.wait()
if not files_to_trash is None:
try:
subprocess.run(['gio', 'trash'] + files_to_trash, capture_output=True)
subprocess.run(['gio', 'trash'] + files_to_trash, capture_output=True, check=True)
except Exception:
pass
@@ -99,5 +104,5 @@ class TarWorker:
def extract(self):
self.stop = False
Gio.Task.new(None, None, None).run_in_thread(self.existing_path)
Gio.Task.new(None, None, None).run_in_thread(self.extract_thread)
GLib.timeout_add(200, self.check_size, self.new_path)