From e58f3a61fef490fe044f439dafa579e2af2f9ceb Mon Sep 17 00:00:00 2001 From: Sergio Kef Date: Mon, 20 Apr 2020 15:11:17 +0200 Subject: [PATCH] Remove logic checking if file has changed --- test/test_archive.py | 32 -------------------------------- youtube_dl/archive.py | 20 +++++--------------- 2 files changed, 5 insertions(+), 47 deletions(-) diff --git a/test/test_archive.py b/test/test_archive.py index 6d731e6db..932c21ba5 100644 --- a/test/test_archive.py +++ b/test/test_archive.py @@ -39,38 +39,6 @@ class TestArchive(unittest.TestCase): def test_archive_not_exists(self): self.assertFalse("dl_id" in self.archive) - def test_archive_last_read_on_write(self): - t1 = self.archive._last_read - self.archive.record_download("dl_id") - t2 = self.archive._last_read - self.assertNotEqual(t1, t2) - - def test_archive_last_read_on_read(self): - t1 = self.archive._last_read - self.archive.record_download("dl_id 1") - t2 = self.archive._last_read - self.assertNotEqual(t1, t2) - - def test_archive_file_not_changed(self): - self.archive.record_download("dl_id") - self.assertFalse(self.archive._file_changed()) - - def test_archive_file_changed(self): - self.archive.record_download("dl_id 1") - with open(self.archive.filepath, "a", encoding="utf-8") as f_out: - sleep(0.01) - f_out.write("dl_id 2\n") - self.assertTrue(self.archive._file_changed()) - - def test_archive_file_changed_exists(self): - self.archive.record_download("dl_id 1") - with open(self.archive.filepath, "a", encoding="utf-8") as f_out: - sleep(0.01) - f_out.write("dl_id 2\n") - self.assertTrue(self.archive._file_changed()) - self.assertFalse("dl_id 2" in self.archive._data) - self.assertTrue("dl_id 2" in self.archive) - def test_archive_multiple_writes(self): self.archive.record_download("dl_id 1") self.archive.record_download("dl_id 2") diff --git a/youtube_dl/archive.py b/youtube_dl/archive.py index 643e48ffb..13106277b 100644 --- a/youtube_dl/archive.py +++ b/youtube_dl/archive.py @@ -18,25 +18,22 @@ class Archive(object): _data: set Container for holding a cache of the archive _disabled: bool When true, all functions are effectively void filepath: str The filepath of the archive - _last_read: float The last modification date of the archive file Methods: __contains__ Checks a video id (archive id) exists in archive - _file_changed Checks if file has been modified since last read _read_archive Reads archive from disk record_download Adds a new download to archive """ def __init__(self, filepath): """ Instantiate Archive - filepath: str or None. The filepath of the archive. If None is provided - instance can still be used but it's effectively - doing nothing.""" + filepath: str or None. The filepath of the archive. If None or empty + string is provided instance can still be used + but it's effectively doing nothing.""" self.filepath = None if filepath == "" else filepath self._disabled = self.filepath is None self._data = set() - self._last_read = 0 def record_download(self, archive_id): """ Records a new archive_id in the archive """ @@ -45,23 +42,16 @@ class Archive(object): with locked_file(self.filepath, "a", encoding="utf-8") as file_out: file_out.write(archive_id + "\n") - self._last_read = compat_st_mtime(self.filepath) self._data.add(archive_id) - def _file_changed(self): - """ Checks if file has been modified, using system Modification Date """ - if os.path.exists(self.filepath): - return self._last_read < compat_st_mtime(self.filepath) - return True - def _read_file(self): """ Reads the data from archive file """ - if self._disabled or not self._file_changed(): + if self._disabled: return + try: with locked_file(self.filepath, "r", encoding="utf-8") as file_in: self._data.update(line.strip() for line in file_in) - self._last_read = compat_st_mtime(self.filepath) except IOError as err: if err.errno != errno.ENOENT: raise