From: Christian Heller Date: Wed, 26 Feb 2025 13:25:26 +0000 (+0100) Subject: Fix sync no longer removing files and their entries. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/static/calendar?a=commitdiff_plain;h=6e39f774ba7d958086fe543544d8551ea160f983;p=ytplom Fix sync no longer removing files and their entries. --- diff --git a/src/ytplom/http.py b/src/ytplom/http.py index 8db6e50..c4af15d 100644 --- a/src/ytplom/http.py +++ b/src/ytplom/http.py @@ -127,7 +127,7 @@ class _TaskHandler(PlomHttpHandler): file.set_flags({FILE_FLAGS[FlagName('delete')]}) file.save(conn) conn.commit() - file.ensure_unlinked_if_deleted(conn) + file.ensure_unlinked_if_no_living_owners(conn) self._redirect(Path(self.postvars.first_for('redir_target'))) def _update_file(self) -> None: @@ -176,7 +176,7 @@ class _TaskHandler(PlomHttpHandler): def _purge_deleted_files(self) -> None: with DbConn() as conn: - for file in VideoFile.get_deleteds(conn): + for file in VideoFile.get_all_deleted(conn): self.server.player.remove_by_digest(file.digest) VideoFile.purge_deleteds(conn) conn.commit() diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index bbb959c..ff7b588 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -408,13 +408,13 @@ class VideoFile(DbData): return file if isinstance(file, VideoFile) else cls(None, Path('')) @classmethod - def get_all(cls, conn: DbConn) -> list[Self]: + def get_all_non_deleted(cls, conn: DbConn) -> list[Self]: """Extend super by excluding deleteds.""" return [f for f in super().get_all(conn) if not f.deleted] @classmethod - def get_deleteds(cls, conn: DbConn) -> list[Self]: - """Get _only_ deleteds.""" + def get_all_deleted(cls, conn: DbConn) -> list[Self]: + """Get only deleteds.""" return [f for f in super().get_all(conn) if f.deleted] @classmethod @@ -435,9 +435,9 @@ class VideoFile(DbData): needed_tags_seen: TagSet = TagSet(set()), show_absent: bool = False ) -> list[Self]: - """Return cls.get_all matching provided filter criteria.""" + """Return cls.get_all_non_deleted matching provided filter criteria.""" return [ - f for f in cls.get_all(conn) + f for f in cls.get_all_non_deleted(conn) if (show_absent or f.present) and str(filter_path).lower() in str(f.rel_path).lower() and (cls.tags_prefilter_needed.are_all_in(f.tags) @@ -458,7 +458,7 @@ class VideoFile(DbData): def all_tags_showable(cls, conn) -> TagSet: """Show all used tags passing .tags_display_whitelist.""" tags = TagSet() - for file in cls.get_all(conn): + for file in cls.get_all_non_deleted(conn): tags.add(file.tags.whitelisted(cls.tags_display_whitelist)) return tags @@ -470,7 +470,7 @@ class VideoFile(DbData): def unused_tags(self, conn: DbConn) -> TagSet: """Return tags used among other VideoFiles, not in self.""" tags = TagSet() - for file in self.get_all(conn): + for file in self.get_all_non_deleted(conn): tags.add(file.tags.all_not_in(self.tags).whitelisted( self.tags_display_whitelist)) return tags @@ -525,11 +525,12 @@ class VideoFile(DbData): """Return if flag of flag_name is set in flags field.""" return bool(self.flags & FILE_FLAGS[flag_name]) - def ensure_unlinked_if_deleted(self, conn: DbConn) -> None: - """If 'delete' flag set and no undeleted owner, ensure unlinked.""" - if self.full_path in [f.full_path for f in self.get_all(conn)]: + def ensure_unlinked_if_no_living_owners(self, conn: DbConn) -> None: + """If 'delete' flag set and no undeleted owner, unlink.""" + if self.full_path in [f.full_path + for f in self.get_all_non_deleted(conn)]: return - if self.is_flag_set(FlagName('delete')) and self.present: + if self.present: self.unlink_locally() def unlink_locally(self) -> None: @@ -540,7 +541,7 @@ class VideoFile(DbData): @classmethod def purge_deleteds(cls, conn: DbConn) -> None: """For all of .is_flag_set("deleted"), remove file _and_ DB entry.""" - for file in cls.get_deleteds(conn): + for file in cls.get_all_deleted(conn): if file.present: file.unlink_locally() print(f'SYNC: purging off DB: {file.digest.b64} ({file.rel_path})') @@ -800,7 +801,8 @@ class DownloadsManager: def _sync_db(self): with DbConn() as conn: - known_paths = [file.rel_path for file in VideoFile.get_all(conn)] + known_paths = [file.rel_path for + file in VideoFile.get_all_non_deleted(conn)] old_cwd = Path.cwd() chdir(PATH_DOWNLOADS) for path in [p for p in Path('.').iterdir() if p.is_file()]: @@ -820,9 +822,9 @@ class DownloadsManager: 'present', str(path), VideoFile.get_by_yt_id(conn, yt_id).digest.b64) - for file in VideoFile.get_deleteds(conn): - file.ensure_unlinked_if_deleted(conn) - self._files = VideoFile.get_all(conn) + for file in VideoFile.get_all_deleted(conn): + file.ensure_unlinked_if_no_living_owners(conn) + self._files = VideoFile.get_all_non_deleted(conn) chdir(old_cwd) def last_update_for(self,