diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 38e61ab47e..05d30ca5fc 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1261,6 +1261,8 @@ class DB: def close(self, force=False, unload_formatter_functions=True): if getattr(self, '_conn', None) is not None: + if self.prefs['expire_old_trash_after'] == 0: + self.expire_old_trash(0) if unload_formatter_functions: try: unload_user_template_functions(self.library_id) @@ -2021,7 +2023,7 @@ class DB: mtime = st.st_mtime except OSError: mtime = 0 - if mtime + expire_age_in_seconds <= now: + if mtime + expire_age_in_seconds <= now or expire_age_in_seconds <= 0: removals.append(x.path) for x in removals: rmtree_with_retry(x) diff --git a/src/calibre/gui2/trash.py b/src/calibre/gui2/trash.py index aa210d3b6b..a6f0c91645 100644 --- a/src/calibre/gui2/trash.py +++ b/src/calibre/gui2/trash.py @@ -134,11 +134,15 @@ class TrashView(Dialog): la = QLabel(_('&Permanently delete after:')) self.auto_delete = ad = QSpinBox(self) - ad.setMinimum(1) + ad.setMinimum(0) ad.setMaximum(365) + ad.setSpecialValueText(_('on close')) ad.setValue(int(self.db.pref('expire_old_trash_after', DEFAULT_TRASH_EXPIRY_TIME_SECONDS) / 86400)) ad.setSuffix(_(' days')) - ad.setToolTip(_('Deleted items are permanently deleted automatically after the specified number of days')) + ad.setToolTip(_( + 'Deleted items are permanently deleted automatically after the specified number of days. If set to "on close" they are' + ' deleted whenever the library is closed, that is when switching to another library or exiting calibre.' + )) ad.valueChanged.connect(self.trash_expiry_time_changed) h = QHBoxLayout() h.addWidget(la), h.addWidget(ad), h.addStretch(10)