home · contact · privacy
Fix sync no longer removing files and their entries.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 26 Feb 2025 13:25:26 +0000 (14:25 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 26 Feb 2025 13:25:26 +0000 (14:25 +0100)
src/ytplom/http.py
src/ytplom/misc.py

index 8db6e5052ae9dd1b8e597d07ee59d9ec1f90598c..c4af15d9ff879a20c077fb58b35a851d4886a177 100644 (file)
@@ -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()
index bbb959c8992efecdd4aab069acb7593ec8d94ea1..ff7b588d9d045f8415ca46eb58f5d56cd579bc9a 100644 (file)
@@ -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,