Skip to content

Commit 6e35344

Browse files
committed
prefix all by-name entries
1 parent 74fa538 commit 6e35344

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

nixipfs/src/mirror_tarballs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import subprocess
77
import threading
88
import shlex
9+
import hashlib
10+
import time
911
from pygit2 import clone_repository, GIT_RESET_HARD, Repository
1012
from shutil import copyfile
1113

@@ -48,6 +50,7 @@ def check_presence(target_dir, value):
4850
os.path.join(target_dir, "sha1", value),
4951
os.path.join(target_dir, "sha256", value),
5052
os.path.join(target_dir, "sha512", value),
53+
# TODO: glob this
5154
os.path.join(target_dir, "by-name", value)
5255
]
5356
return [ path for path in paths if os.path.exists(path) ]
@@ -83,7 +86,10 @@ def mirror_file(target_dir, path, name, revision):
8386
if not os.path.exists(os.path.join(sha512_dir, sha512_32)):
8487
os.symlink(os.path.relpath(main_file, start=sha512_dir), os.path.join(sha512_dir, sha512_32))
8588

86-
by_name_dir = os.path.join(target_dir, "by-name")
89+
# do something semi random to avoid collisions
90+
name_prefix = "{}_{}".format(revision, int(time.time()))
91+
by_name_dir = os.path.join(target_dir, "by-name", name_prefix)
92+
os.makedirs(by_name_dir, exist_ok=True)
8793
if not os.path.exists(os.path.join(by_name_dir, name)):
8894
os.symlink(os.path.relpath(main_file, start=by_name_dir), os.path.join(by_name_dir, name))
8995

0 commit comments

Comments
 (0)