Repository: mandarons/icloud-drive-docker
Pull request #107 (2023-01-08 22:40:37)

Pr 104 - tests updated


Patch:
diff --git a/src/sync.py b/src/sync.py
index d8b7137b..8f7b3159 100644
--- a/src/sync.py
+++ b/src/sync.py
@@ -68,12 +68,16 @@ def sync():
                 )
                 if not api.requires_2sa:
                     if "drive" in config and enable_sync_drive:
+                        LOGGER.info("Syncing drive...")
                         sync_drive.sync_drive(config=config, drive=api.drive)
+                        LOGGER.info("Drive synced")
                         drive_sync_interval = config_parser.get_drive_sync_interval(
                             config=config
                         )
                     if "photos" in config and enable_sync_photos:
+                        LOGGER.info("Syncing photos...")
                         sync_photos.sync_photos(config=config, photos=api.photos)
+                        LOGGER.info("Photos synced")
                         photos_sync_interval = config_parser.get_photos_sync_interval(
                             config=config
                         )
diff --git a/src/sync_drive.py b/src/sync_drive.py
index a83f7528..42d21401 100644
--- a/src/sync_drive.py
+++ b/src/sync_drive.py
@@ -97,11 +97,12 @@ def package_exists(item, local_package_path):
             )
             return True
         else:
-            LOGGER.debug(
+            LOGGER.info(
                 f"Changes detected: local_modified_time is {local_package_modified_time}, "
                 + f"remote_modified_time is {remote_package_modified_time}, "
                 + f"local_package_size is {local_package_size} and remote_package_size is {remote_package_size}."
             )
+            rmtree(local_package_path)
     else:
         LOGGER.debug(f"Package {local_package_path} does not exist locally.")
     return False
@@ -139,11 +140,13 @@ def process_package(local_file):
     if "application/zip" == magic_object.from_file(filename=local_file):
         archive_file += ".zip"
         os.rename(local_file, archive_file)
+        LOGGER.info(f"Unpacking {archive_file} to {os.path.dirname(archive_file)}")
         unpack_archive(filename=archive_file, extract_dir=os.path.dirname(archive_file))
         os.remove(archive_file)
     elif "application/gzip" == magic_object.from_file(filename=local_file):
         archive_file += ".gz"
         os.rename(local_file, archive_file)
+        LOGGER.info(f"Unpacking {archive_file} to {os.path.dirname(local_file)}")
         with gzip.GzipFile(filename=archive_file, mode="rb") as gz_file:
             with open(file=local_file, mode="wb") as package_file:
                 copyfileobj(gz_file, package_file)
@@ -193,12 +196,18 @@ def process_file(item, destination_path, filters, files):
     if not wanted_file(filters=filters, file_path=local_file):
         return False
     files.add(local_file)
-    if is_package(item=item):
+    item_is_package = is_package(item=item)
+    if item_is_package:
         if package_exists(item=item, local_package_path=local_file):
+            for f in Path(local_file).glob("**/*"):
+                files.add(str(f))
             return False
     elif file_exists(item=item, local_file=local_file):
         return False
     download_file(item=item, local_file=local_file)
+    if item_is_package:
+        for f in Path(local_file).glob("**/*"):
+            files.add(str(f))
     return True
 
 


Test patch:
diff --git a/tests/test_sync_drive.py b/tests/test_sync_drive.py
index 3a4b0852..94606b77 100644
--- a/tests/test_sync_drive.py
+++ b/tests/test_sync_drive.py
@@ -742,7 +742,7 @@ class TestSyncDrive(unittest.TestCase):
             filters=self.filters,
             remove=False,
         )
-        self.assertTrue(len(actual) == 10)
+        self.assertTrue(len(actual) == 22)
         self.assertTrue(os.path.isdir(os.path.join(self.destination_path, "icloudpy")))
         self.assertTrue(
             os.path.isdir(os.path.join(self.destination_path, "icloudpy", "Test"))
@@ -777,7 +777,7 @@ class TestSyncDrive(unittest.TestCase):
             filters=self.filters,
             remove=True,
         )
-        self.assertTrue(len(actual) == 10)
+        self.assertTrue(len(actual) == 22)
         self.assertTrue(os.path.isdir(os.path.join(self.destination_path, "icloudpy")))
         self.assertTrue(
             os.path.isdir(os.path.join(self.destination_path, "icloudpy", "Test"))
@@ -810,7 +810,7 @@ class TestSyncDrive(unittest.TestCase):
             filters=self.filters,
             remove=False,
         )
-        self.assertTrue(len(actual) == 14)
+        self.assertTrue(len(actual) == 26)
         self.assertTrue(os.path.isdir(os.path.join(self.destination_path, "icloudpy")))
         self.assertTrue(
             os.path.isdir(os.path.join(self.destination_path, "icloudpy", "Test"))