Skip to content

Commit 869f761

Browse files
committed
Separate release assets and skip re-downloading
Currently the script puts all release assets into the same folder called `releases`. So any time 2 release files have the same name, only the last one downloaded is actually saved. A particularly bad example of this is MacDownApp/macdown where all of their releases are named `MacDown.app.zip`. So even though they have 36 releases and all 36 are downloaded, only the last one is actually saved. With this change, each releases' assets are now stored in a fubfolder inside `releases` named after the release name. There could still be edge cases if two releases have the same name, but this is still much safer tha the previous behavior. This change also now checks if the asset file already exists on disk and skips downloading it. This drastically speeds up addiotnal syncs as it no longer downloads every single release every single time. It will now only download new releases which I believe is the expected behavior. closes josegonzalez#126
1 parent fac8e42 commit 869f761

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

bin/github-backup

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,10 @@ class S3HTTPRedirectHandler(HTTPRedirectHandler):
565565

566566

567567
def download_file(url, path, auth):
568+
# Skip downloading release assets if they already exist on disk so we don't redownload on every sync
569+
if os.path.exists(path):
570+
return
571+
568572
request = Request(url)
569573
request.add_header('Accept', 'application/octet-stream')
570574
request.add_header('Authorization', 'Basic '.encode('ascii') + auth)
@@ -958,8 +962,14 @@ def backup_releases(args, repo_cwd, repository, repos_template, include_assets=F
958962

959963
if include_assets:
960964
assets = retrieve_data(args, release['assets_url'])
965+
if len(assets) > 0:
966+
# give release asset files somewhere to live
967+
release_assets_cwd = os.path.join(release_cwd, release_name)
968+
mkdir_p(release_assets_cwd)
969+
970+
# download any release asset files (not including source archives)
961971
for asset in assets:
962-
download_file(asset['url'], os.path.join(release_cwd, asset['name']), get_auth(args))
972+
download_file(asset['url'], os.path.join(release_assets_cwd, asset['name']), get_auth(args))
963973

964974

965975
def fetch_repository(name,

0 commit comments

Comments
 (0)