Skip to content

Commit 7a9455d

Browse files
committed
fix: Prevent duplicate attachment downloads
Fixes bug where attachments were downloaded multiple times with incremented filenames (file.mov, file_1.mov, file_2.mov) when running backups without --skip-existing flag. I should not have used the --skip-existing flag for attachments, it did not do what I thought it did. The correct approach is to always use the manifest to guide what has already been downloaded and what now needs to be done.
1 parent 7b78f06 commit 7a9455d

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

github_backup/github_backup.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -919,12 +919,6 @@ def download_attachment_file(url, path, auth, as_app=False, fine=False):
919919
"error": None,
920920
}
921921

922-
if os.path.exists(path):
923-
metadata["success"] = True
924-
metadata["http_status"] = 200 # Assume success if already exists
925-
metadata["size_bytes"] = os.path.getsize(path)
926-
return metadata
927-
928922
# Create simple request (no API query params)
929923
request = Request(url)
930924
request.add_header("Accept", "application/octet-stream")
@@ -1337,10 +1331,10 @@ def download_attachments(
13371331
attachments_dir = os.path.join(item_cwd, "attachments", str(number))
13381332
manifest_path = os.path.join(attachments_dir, "manifest.json")
13391333

1340-
# Load existing manifest if skip_existing is enabled
1334+
# Load existing manifest to prevent duplicate downloads
13411335
existing_urls = set()
13421336
existing_metadata = []
1343-
if args.skip_existing and os.path.exists(manifest_path):
1337+
if os.path.exists(manifest_path):
13441338
try:
13451339
with open(manifest_path, "r") as f:
13461340
existing_manifest = json.load(f)
@@ -1395,9 +1389,6 @@ def download_attachments(
13951389
filename = get_attachment_filename(url)
13961390
filepath = os.path.join(attachments_dir, filename)
13971391

1398-
# Check for collision BEFORE downloading
1399-
filepath = resolve_filename_collision(filepath)
1400-
14011392
# Download and get metadata
14021393
metadata = download_attachment_file(
14031394
url,

0 commit comments

Comments
 (0)