From b5cacbf711166f665947ea341ec70a7c9264c779 Mon Sep 17 00:00:00 2001 From: VodBox Date: Mon, 11 Mar 2024 14:09:49 +1100 Subject: [PATCH] fix: correct exists check for segment linker May actually just be a bug with the exists check in the super class SegmentGetter? --- downloader/downloader/main.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/downloader/downloader/main.py b/downloader/downloader/main.py index 871e628..60c93d0 100644 --- a/downloader/downloader/main.py +++ b/downloader/downloader/main.py @@ -712,6 +712,25 @@ class SegmentLinker(SegmentGetter): self.done = gevent.event.Event() # Our parent's connection pool, but we'll replace it if there's any issues + def exists(self): + """Look for an existing link to the segment. Return bool.""" + dirname = os.path.dirname(self.prefix) + try: + candidates = os.listdir(dirname) + except OSError as e: + # on ENOENT (doesn't exist), return false + if e.errno != errno.ENOENT: + raise + return False + full_prefix = "{}-full".format(self.prefix) + return any( + os.path.join(dirname, candidate).startswith(full_prefix) + # There's almost no way a matching tombstone could already exist, but just in case + # we'll make sure it isn't counted. + and not candidate.endswith(".tombstone") + for candidate in candidates + ) + def make_path_prefix(self): return os.path.join( self.base_dir,