Skip to content
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
15 changes: 10 additions & 5 deletions src/vorta/borg/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,16 @@ def prepare(cls, profile):
exclude_dirs.append(expanded_directory)

if exclude_dirs:
pattern_file = tempfile.NamedTemporaryFile('w', delete=True)
pattern_file.write('\n'.join(exclude_dirs))
pattern_file.flush()
cmd.extend(['--exclude-from', pattern_file.name])
ret['cleanup_files'].append(pattern_file)
pattern_file = tempfile.NamedTemporaryFile('w', delete=False)
try:
pattern_file.write('\n'.join(exclude_dirs))
pattern_file.flush()
cmd.extend(['--exclude-from', pattern_file.name])
ret['cleanup_files'].append(pattern_file)
except Exception:
pattern_file.close()
os.unlink(pattern_file.name)
raise

# Currently not in use, but may be added back to the UI later.
# if profile.exclude_if_present is not None:
Expand Down
8 changes: 6 additions & 2 deletions src/vorta/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def set_timer_for_profile(self, profile_id: int) -> None:
else:
# int to big to pass it to qt which expects a c++ int
# wait 15 min for regular reschedule
logger.debug(f"Couldn't schedule for {next_time} because " f"timer value {timer_ms} too large.")
logger.debug(f"Couldn't schedule for {next_time} because timer value {timer_ms} too large.")

self.timers[profile_id] = {
'dt': next_time,
Expand Down Expand Up @@ -499,7 +499,11 @@ def post_backup_tasks(self, profile_id: int) -> None:
"""
Pruning and checking after successful backup.
"""
profile = BackupProfileModel.get(id=profile_id)
profile = BackupProfileModel.get_or_none(id=profile_id)
if profile is None:
logger.warning('Profile %s not found for post-backup tasks', profile_id)
return

notifier = VortaNotifications.pick()
logger.info('Doing post-backup jobs for %s', profile.name)
if profile.prune_on:
Expand Down
3 changes: 2 additions & 1 deletion src/vorta/views/archive_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ def save_archive_template(self, tpl, key):
preview = self.tr('Preview: %s') % format_archive_name(profile, tpl)
setattr(profile, key, tpl)
profile.save()
except Exception:
except (KeyError, ValueError, AttributeError) as e:
preview = self.tr('Error in archive name template.')
logger.warning('Invalid archive name template: %s', e)

if key == 'new_archive_name':
self.archiveNamePreview.setText(preview)
Expand Down
8 changes: 7 additions & 1 deletion src/vorta/views/base_tab.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import annotations

import logging
from typing import Any, Callable

from PyQt6.QtWidgets import QApplication

from vorta.store.models import BackupProfileModel, RepoModel

logger = logging.getLogger(__name__)

ProfileProvider = Callable[[], BackupProfileModel | None]


Expand All @@ -28,7 +31,10 @@ def _default_profile_provider(self) -> BackupProfileModel | None:
current_profile = getattr(self.window(), 'current_profile', None)
if current_profile is None:
return None
return BackupProfileModel.get(id=current_profile.id)
profile = BackupProfileModel.get_or_none(id=current_profile.id)
if profile is None:
logger.warning(f"Profile with id {current_profile.id} no longer exists")
return profile

def current_profile(self) -> BackupProfileModel | None:
return self._profile_provider()
Expand Down
5 changes: 4 additions & 1 deletion src/vorta/views/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ def on_close_window(self):
self.close()

def get_current_profile(self):
return BackupProfileModel.get(id=self.current_profile.id)
profile = BackupProfileModel.get_or_none(id=self.current_profile.id)
if profile is None:
logging.warning(f"Profile with id {self.current_profile.id} no longer exists")
return profile

def set_icons(self):
self.profileAddButton.setIcon(get_colored_icon('plus'))
Expand Down
3 changes: 2 additions & 1 deletion src/vorta/views/repo_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ def ssh_copy_to_clipboard_action(self):
ssh_key_filename = self.sshComboBox.itemData(index)
ssh_key_path = os.path.expanduser(f'~/.ssh/{ssh_key_filename}.pub')
if os.path.isfile(ssh_key_path):
pub_key = open(ssh_key_path).read().strip()
with open(ssh_key_path) as f:
pub_key = f.read().strip()
clipboard = QApplication.clipboard()
clipboard.setText(pub_key)

Expand Down