mirror of
https://github.com/borgbase/vorta
synced 2025-01-02 21:25:48 +00:00
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:
parent
71af54f59b
commit
7eedd39319
1 changed files with 32 additions and 5 deletions
|
@ -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 @@ def finished_event(self, result):
|
|||
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 @@ def prepare(cls, profile, archive_name, selected_files: ExtractTree, destination
|
|||
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 @@ def prepare(cls, profile, archive_name, selected_files: ExtractTree, destination
|
|||
|
||||
return ret
|
||||
|
||||
def process_result(self, result):
|
||||
def process_result(self, result: dict):
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue