Skip to content

Reload database when extracting database over it #704

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

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
8 changes: 2 additions & 6 deletions src/vorta/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
import signal
import sys

import peewee
from vorta._version import __version__
from vorta.config import SETTINGS_DIR
from vorta.log import init_logger
from vorta.models import init_db
from vorta.models import connect_db
from vorta.updater import get_updater
from vorta.utils import parse_args

Expand All @@ -28,9 +26,7 @@ def main():

init_logger(background=want_background)

# Init database
sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'))
init_db(sqlite_db)
connect_db()

# Init app after database is available
from vorta.application import VortaApp
Expand Down
5 changes: 4 additions & 1 deletion src/vorta/borg/borg_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from subprocess import Popen, PIPE

from vorta.i18n import trans_late
from vorta.models import EventLogModel, BackupProfileMixin
from vorta.models import EventLogModel, BackupProfileMixin, connect_db
from vorta.utils import borg_compat, pretty_bytes
from vorta.keyring.abc import get_keyring
from vorta.keyring.db import VortaDBKeyring
Expand Down Expand Up @@ -239,6 +239,9 @@ def read_async(fd):
except ValueError:
result['data'] = stdout

if result['cmd'][1] == "extract":
connect_db()

log_entry.returncode = p.returncode
log_entry.repo_url = self.params.get('repo_url', None)
log_entry.save()
Expand Down
7 changes: 7 additions & 0 deletions src/vorta/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import peewee as pw
from playhouse.migrate import SqliteMigrator, migrate

from vorta.config import SETTINGS_DIR
from vorta.i18n import trans_late
from vorta.utils import slugify

Expand Down Expand Up @@ -252,6 +253,12 @@ def get_misc_settings():
return settings


def connect_db():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not have init_db() only?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump. Is connect_db() even needed? Why not move it all to init_db()? For tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tried to remove it and it broke the tests. I could try to change the test code, but based on past experience changing it makes things worse.

# Init database
sqlite_db = pw.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'))
init_db(sqlite_db)


def init_db(con=None):
if con is not None:
os.umask(0o0077)
Expand Down
2 changes: 2 additions & 0 deletions src/vorta/views/archive_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ def receive():

def extract_archive_result(self, result):
self._toggle_all_buttons(True)
if result['returncode'] == 0:
self.list_action()

def update_mount_button_text(self):
archive_name = self.selected_archive_name()
Expand Down