anki/qt/aqt/forms
RumovZ f3c8857421
Backups (#1685)
* Add zstd dep

* Implement backend backup with zstd

* Implement backup thinning

* Write backup meta

* Use new file ending anki21b

* Asynchronously backup on collection close in Rust

* Revert "Add zstd dep"

This reverts commit 3fcb2141d2be15f907269d13275c41971431385c.

* Add zstd again

* Take backup col path from col struct

* Fix formatting

* Implement backup restoring on backend

* Normalize restored media file names

* Refactor `extract_legacy_data()`

A bit cumbersome due to borrowing rules.

* Refactor

* Make thinning calendar-based and gradual

* Consider last kept backups of previous stages

* Import full apkgs and colpkgs with backend

* Expose new backup settings

* Test `BackupThinner` and make it deterministic

* Mark backup_path when closing optional

* Delete leaky timer

* Add progress updates for restoring media

* Write restored collection to tempfile first

* Do collection compression in the background thread

This has us currently storing an uncompressed and compressed copy of
the collection in memory (not ideal), but means the collection can be
closed without waiting for compression to complete. On a large collection,
this takes a close and reopen from about 0.55s to about 0.07s. The old
backup code for comparison: about 0.35s for compression off, about
8.5s for zip compression.

* Use multithreading in zstd compression

On my system, this reduces the compression time of a large collection
from about 0.55s to 0.08s.

* Stream compressed collection data into zip file

* Tweak backup explanation

+ Fix incorrect tab order for ignore accents option

* Decouple restoring backup and full import

In the first case, no profile is opened, unless the new collection
succeeds to load.
In the second case, either the old collection is reloaded or the new one
is loaded.

* Fix number gap in Progress message

* Don't revert backup when media fails but report it

* Tweak error flow

* Remove native BackupLimits enum

* Fix type annotation

* Add thinning test for whole year

* Satisfy linter

* Await async backup to finish

* Move restart disclaimer out of backup tab

Should be visible regardless of the current tab.

* Write restored collection in chunks

* Refactor

* Write media in chunks and refactor

* Log error if removing file fails

* join_backup_task -> await_backup_completion

* Refactor backup.rs

* Refactor backup meta and collection extraction

* Fix wrong error being returned

* Call sync_all() on new collection

* Add ImportError

* Store logger in Backend, instead of creating one on demand

init_backend() accepts a Logger rather than a log file, to allow other
callers to customize the logger if they wish.

In the future we may want to explore using the tracing crate as an
alternative; it's a bit more ergonomic, as a logger doesn't need to be
passed around, and it plays more nicely with async code.

* Sync file contents prior to rename; sync folder after rename.

* Limit backup creation to once per 30 min

* Use zstd::stream::copy_decode

* Make importing abortable

* Don't revert if backup media is aborted

* Set throttle implicitly

* Change force flag to minimum_backup_interval

* Don't attempt to open folders on Windows

* Join last backup thread before starting new one

Also refactor.

* Disable auto sync and backup when restoring again

* Force backup on full download

* Include the reason why a media file import failed, and the file path

- Introduce a FileIoError that contains a string representation of
the underlying I/O error, and an associated path. There are a few
places in the code where we're currently manually including the filename
in a custom error message, and this is a step towards a more consistent
approach (but we may be better served with a more general approach in
the future similar to Anyhow's .context())
- Move the error message into importing.ftl, as it's a bit neater
when error messages live in the same file as the rest of the messages
associated with some functionality.

* Fix importing of media files

* Minor wording tweaks

* Save an allocation

I18n strings with replacements are already strings, so we can skip the
extra allocation. Not that it matters here at all.

* Terminate import if file missing from archive

If a third-party tool is creating invalid archives, the user should know
about it. This should be rare, so I did not attempt to make it
translatable.

* Skip multithreaded compression on small collections

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2022-03-07 15:11:31 +10:00
..
__init__.py Add a flag to allow loading the fields dialog in a web view (#1706) 2022-03-03 22:45:26 +10:00
about_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
about.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
about.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
addcards_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
addcards.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
addcards.ui Remove unused actions from ui files (#1655) 2022-02-11 10:15:36 +10:00
addfield_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
addfield.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
addfield.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
addmodel_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
addmodel.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
addmodel.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
addonconf_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
addonconf.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
addonconf.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
addons_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
addons.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
addons.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
browser_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
browser.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
browser.ui View menu (#1668) 2022-02-17 16:31:46 +10:00
browserdisp_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
browserdisp.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
browserdisp.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
browseropts_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
browseropts.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
browseropts.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
build_ui_qt5.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
build_ui_qt6.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
build_ui.py remove a few unnecessary PyQt workarounds 2021-10-24 14:24:35 +10:00
BUILD.bazel improve PyQt install 2021-10-23 10:56:17 +10:00
changemap_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
changemap.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
changemap.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
changemodel_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
changemodel.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
changemodel.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
clayout_top_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
clayout_top.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
clayout_top.ui Increased max visible items from clayout_top.ui (#1425) 2021-10-14 19:36:04 +10:00
compile.bzl build all the UI files in one go 2021-10-16 09:20:20 +10:00
customstudy_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
customstudy.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
customstudy.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
dconf_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
dconf.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
dconf.ui split deck description into separate screen linked from overview 2021-04-22 21:03:16 +10:00
debug_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
debug.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
debug.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
editaddon_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
editaddon.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
editaddon.ui update designer references 2020-11-17 19:55:18 +10:00
editcurrent_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
editcurrent.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
editcurrent.ui update designer references 2020-11-17 19:55:18 +10:00
edithtml_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
edithtml.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
edithtml.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
emptycards_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
emptycards.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
emptycards.ui update designer references 2020-11-17 19:55:18 +10:00
exporting_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
exporting.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
exporting.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
fields_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
fields_web_qt6.py Add a flag to allow loading the fields dialog in a web view (#1706) 2022-03-03 22:45:26 +10:00
fields_web.py Add a flag to allow loading the fields dialog in a web view (#1706) 2022-03-03 22:45:26 +10:00
fields_web.ui Add a flag to allow loading the fields dialog in a web view (#1706) 2022-03-03 22:45:26 +10:00
fields.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
fields.ui Editor Field Descriptions (#1476) 2021-11-06 09:42:48 +10:00
filtered_deck_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
filtered_deck.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
filtered_deck.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
finddupes_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
finddupes.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
finddupes.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
findreplace_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
findreplace.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
findreplace.ui switch to new-style PyQt scoped enums and Qt6 2021-10-15 12:57:19 +10:00
getaddons_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
getaddons.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
getaddons.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
icons.qrc fix generated code symlinks again 2022-01-24 16:59:37 +10:00
importing_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
importing.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
importing.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
main_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
main.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
main.ui View menu (#1668) 2022-02-17 16:31:46 +10:00
modelopts_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
modelopts.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
modelopts.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
models_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
models.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
models.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
preferences_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
preferences.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
preferences.ui Backups (#1685) 2022-03-07 15:11:31 +10:00
preview_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
preview.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
preview.ui initial Bazel conversion 2020-11-01 14:26:58 +10:00
profiles_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
profiles.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
profiles.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
progress_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
progress.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
progress.ui update designer references 2020-11-17 19:55:18 +10:00
reposition_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
reposition.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
reposition.ui require reposition to start at 0; cap maximum 2021-06-01 10:09:24 +10:00
setgroup_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
setgroup.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
setgroup.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
setlang_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
setlang.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
setlang.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
stats_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
stats.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
stats.ui update designer references 2020-11-17 19:55:18 +10:00
studydeck_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
studydeck.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
studydeck.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
synclog_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
synclog.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
synclog.ui initial Bazel conversion 2020-11-01 14:26:58 +10:00
taglimit_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
taglimit.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
taglimit.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00
template_qt6.py fix generated code symlinks again 2022-01-24 16:59:37 +10:00
template.py generate pyqt6 forms 2021-10-15 12:57:19 +10:00
template.ui update TR references in .ui files 2021-03-26 15:03:51 +10:00