Skip to content

Commit 62dcd6b

Browse files
committed
Add sha256 validation
1 parent 3fd629e commit 62dcd6b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: apt-sync.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def mkdir_with_dot_tmp(folder: Path)->Tuple[Path, Path]:
9999
tmpdir.mkdir(parents=True, exist_ok=True)
100100
return (folder, tmpdir)
101101

102+
def CalcFileSha256(filname):
103+
''' calculate file sha256 '''
104+
with open(filname, "rb") as f:
105+
sha256obj = hashlib.sha256()
106+
sha256obj.update(f.read())
107+
hash_value = sha256obj.hexdigest()
108+
return hash_value
109+
102110
def move_files_in(src: Path, dst: Path):
103111
empty = True
104112
for file in src.glob('*'):
@@ -237,8 +245,8 @@ def collect_tmp_dir():
237245
dest_dir.mkdir(parents=True, exist_ok=True)
238246
if dest_filename.suffix == '.deb':
239247
deb_set[str(dest_filename.relative_to(dest_base_dir))] = pkg_size
240-
if dest_filename.is_file() and dest_filename.stat().st_size == pkg_size:
241-
print(f"Skipping {pkg_filename}, size {pkg_size}")
248+
if dest_filename.is_file() and ( dest_filename.stat().st_size == pkg_size and CalcFileSha256(dest_filename) == pkg_checksum):
249+
print(f"Skipping {pkg_filename}, size {pkg_size}, sha256 {pkg_checksum}")
242250
continue
243251

244252
pkg_url=f"{base_url}/{pkg_filename}"

0 commit comments

Comments
 (0)