Skip to content

Fix bug with incorrect renaming of archives after aborting edit #2213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/vorta/borg/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@


class BorgRenameJob(BorgJob):
def started_event(self):
self.app.backup_started_event.emit()
self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Renaming archive…')}")

def log_event(self, msg):
self.app.backup_log_event.emit(msg)

Expand Down Expand Up @@ -36,3 +40,5 @@ def process_result(self, result):
renamed_archive = ArchiveModel.get(name=result['params']['old_archive_name'], repo=repo)
renamed_archive.name = result['params']['new_archive_name']
renamed_archive.save()

self.app.backup_progress_event.emit(f"[{self.params['profile_name']}] {self.tr('Archive renamed.')}")
28 changes: 25 additions & 3 deletions src/vorta/views/archive_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(self, parent=None, app=None):
"""Init."""
super().__init__(parent)
self.setupUi(parent)
self.is_editing = False # track if the cell edit was completed or canceled
self.mount_points = {} # mapping of archive name to mount point
self.repo_mount_point: Optional[str] = None # mount point of whole repo
self.menu = None
Expand Down Expand Up @@ -111,10 +112,11 @@ def __init__(self, parent=None, app=None):
self.archiveTable.setTextElideMode(QtCore.Qt.TextElideMode.ElideLeft)
self.archiveTable.setAlternatingRowColors(True)
self.archiveTable.cellDoubleClicked.connect(self.cell_double_clicked)
self.archiveTable.cellChanged.connect(self.cell_changed)
self.archiveTable.setSortingEnabled(True)
self.archiveTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.archiveTable.customContextMenuRequested.connect(self.archiveitem_contextmenu)
edit_delegate = self.archiveTable.itemDelegate()
edit_delegate.closeEditor.connect(self.on_editing_finished)

# shortcuts
shortcut_copy = QShortcut(QKeySequence.StandardKey.Copy, self.archiveTable)
Expand Down Expand Up @@ -827,42 +829,62 @@ def cell_double_clicked(self, row=None, column=None):
if column == 4:
item = self.archiveTable.item(row, column)
self.renamed_archive_original_name = item.text()
self.is_editing = True
item.setFlags(item.flags() | QtCore.Qt.ItemFlag.ItemIsEditable)
self.archiveTable.editItem(item)

def on_editing_finished(self, editor, hint):
"""Called when the user finishes editing a cell (By pressing Enter or clicking away)."""
if not self.is_editing:
return

row = self.archiveTable.currentRow()
column = self.archiveTable.currentColumn()

self.cell_changed(row, column)

def cell_changed(self, row, column):
# return if this is not a name change
if column != 4:
if column != 4 or not self.is_editing:
return

item = self.archiveTable.item(row, column)
new_name = item.text()
profile = self.profile()

# if the name hasn't changed or if this slot is called when first repopulating the table, do nothing.
if new_name == self.renamed_archive_original_name or not self.renamed_archive_original_name:
if new_name == self.renamed_archive_original_name:
self.is_editing = False
return

# if new name is blank, revert to the original name
if not new_name:
item.setText(self.renamed_archive_original_name)
self._set_status(self.tr('Archive name cannot be blank.'))
self.is_editing = False
return

# check if the new name already exists
new_name_exists = ArchiveModel.get_or_none(name=new_name, repo=profile.repo)
if new_name_exists is not None:
self._set_status(self.tr('An archive with this name already exists.'))
item.setText(self.renamed_archive_original_name)
self.is_editing = False
return

params = BorgRenameJob.prepare(profile, self.renamed_archive_original_name, new_name)
if not params['ok']:
self._set_status(params['message'])
self.is_editing = False
return

self._set_status(self.tr('Renaming archive...'))
job = BorgRenameJob(params['cmd'], params, self.profile().repo.id)
job.updated.connect(self._set_status)
job.result.connect(self.rename_result)
self._toggle_all_buttons(False)
self.app.jobs_manager.add_job(job)
self.is_editing = False

def row_of_archive(self, archive_name):
items = self.archiveTable.findItems(archive_name, QtCore.Qt.MatchFlag.MatchExactly)
Expand Down
Loading