Implement extracting exactly the selected files.

* src/vorta/borg/extract.py (BorgExtractJob.prepare): Use `patterns-from` to include only the selected items.
This commit is contained in:
real-yfprojects 2022-05-13 13:49:18 +02:00
parent 71af54f59b
commit 7eedd39319
No known key found for this signature in database
GPG Key ID: 00F630DFDEE25747
1 changed files with 32 additions and 5 deletions

View File

@ -1,4 +1,9 @@
from vorta.views.extract_dialog import ExtractTree
import tempfile
from PyQt5.QtCore import QModelIndex, Qt
from vorta.views.extract_dialog import ExtractTree, FileData
from vorta.views.partials.treemodel import FileSystemItem, path_to_str
from .borg_job import BorgJob
@ -15,7 +20,7 @@ class BorgExtractJob(BorgJob):
self.app.backup_progress_event.emit(self.tr('Restored files from archive.'))
@classmethod
def prepare(cls, profile, archive_name, selected_files: ExtractTree, destination_folder):
def prepare(cls, profile, archive_name, model: ExtractTree, destination_folder):
ret = super().prepare(profile)
if not ret['ok']:
return ret
@ -25,8 +30,30 @@ class BorgExtractJob(BorgJob):
cmd = ['borg', 'extract', '--list', '--info', '--log-json']
cmd.append(f'{profile.repo.url}::{archive_name}')
for s in selected_files: # TODO
cmd.append(s)
# process selected items
# all items will be excluded beside the one actively selected in the
# dialog.
# Unselected (and excluded) parent folders will be restored by borg
# but without the metadata stored in the archive.
pattern_file = tempfile.NamedTemporaryFile('w', delete=False)
pattern_file.write("P fm\n")
indexes = [QModelIndex()]
while indexes:
index = indexes.pop()
for i in range(model.rowCount(index)):
new_index = model.index(i, 0, index)
indexes.append(new_index)
item: FileSystemItem[FileData] = new_index.internalPointer()
if item.data.checkstate == Qt.CheckState.Checked:
pattern_file.write("+ " + path_to_str(item.path) + "\n")
pattern_file.write("- *\n")
pattern_file.flush()
pattern_file.close() # wont delete temp file
cmd.extend(['--patterns-from', pattern_file.name])
ret['ok'] = True
ret['cmd'] = cmd
@ -34,5 +61,5 @@ class BorgExtractJob(BorgJob):
return ret
def process_result(self, result):
def process_result(self, result: dict):
pass