Skip to content

Commit 1750d0e

Browse files
authored
Merge pull request #448 from Iamrodos/fix/attachment-duplicate-downloads
fix: Prevent duplicate attachment downloads (with tests)
2 parents 7b78f06 + e4d1c78 commit 1750d0e

File tree

6 files changed

+396
-11
lines changed

6 files changed

+396
-11
lines changed

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: "test"
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
pull_request:
7+
branches:
8+
- "*"
9+
push:
10+
branches:
11+
- "main"
12+
- "master"
13+
14+
jobs:
15+
test:
16+
name: test
17+
runs-on: ubuntu-24.04
18+
strategy:
19+
matrix:
20+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v5
25+
with:
26+
fetch-depth: 0
27+
- name: Setup Python
28+
uses: actions/setup-python@v6
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
cache: "pip"
32+
- run: pip install -r release-requirements.txt
33+
- run: pytest tests/ -v

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,

pytest.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[pytest]
2+
testpaths = tests
3+
python_files = test_*.py
4+
python_classes = Test*
5+
python_functions = test_*
6+
addopts = -v

release-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ colorama==0.4.6
88
docutils==0.22.3
99
flake8==7.3.0
1010
gitchangelog==3.0.4
11+
pytest==8.3.3
1112
idna==3.11
1213
importlib-metadata==8.7.0
1314
jaraco.classes==3.4.0

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for python-github-backup."""

0 commit comments

Comments
 (0)