def createVendor(vendordir, cratedir):
"We extract each crate, create an empty .cargo-ok file, calculate sha256 sum for every file inside the crate and crate file itself and put it into .cargo-checksum.json"
crate_path = ""
- crate_checksums = []
- crate_files = []
+ crate_files, crate_checksums = [], []
makedirs(vendordir, exist_ok=True)
for crate in glob(f"{cratedir}/*.crate"):
with tarfile.open(crate, 'r:*') as archive:
archive.extractall(path=vendordir, filter='data')
- crate_path = f"{vendordir}/{crate[crate.rfind('/')+1:].replace('.crate', '')}"
- open(f"{crate_path}/.cargo-ok", "a").close()
- for root, dirs, files in walk(f"{crate_path}"):
- crate_files.extend(join(root, name) for name in files)
- for file in crate_files:
- with open(file, "rb") as opened_file:
- crate_checksums.append(sha256(opened_file.read()).hexdigest())
- with open(f"{crate_path}/.cargo-checksum.json", "w") as crate_json:
- with open(crate, 'rb') as crate_file:
- json.dump({"files": dict(zip([file.replace(f"{crate_path}/", "") for file in crate_files], crate_checksums)), "package": sha256(crate_file.read()).hexdigest()}, crate_json)
- crate_files = []
- crate_checksums = []
+ crate_path = f"{vendordir}/{crate[crate.rfind('/')+1:].replace('.crate', '')}"
+ open(f"{crate_path}/.cargo-ok", "a").close()
+ for root, dirs, files in walk(f"{crate_path}"):
+ crate_files.extend(join(root, name) for name in files)
+ for file in crate_files:
+ with open(file, "rb") as opened_file:
+ crate_checksums.append(sha256(opened_file.read()).hexdigest())
+ with open(f"{crate_path}/.cargo-checksum.json", "w") as crate_json:
+ with open(crate, 'rb') as crate_file:
+ json.dump({"files": dict(zip([file.replace(f"{crate_path}/", "") for file in crate_files], crate_checksums)), "package": sha256(crate_file.read()).hexdigest()}, crate_json)
+ crate_files, crate_checksums = [], []
if __name__ == "__main__":
import argparse
parser.add_argument("-c", "--crates", help="Directory with downloaded .crate files to vendor")
args = parser.parse_args()
- workdir = args.directory
- cratedir = args.crates
-
- createVendor(f"{workdir}/vendor", cratedir)
+ createVendor(f"{args.directory}/vendor", args.crates)
https://static.crates.io/crates/serde_yaml/serde_yaml-0.9.34+deprecated.crate \
https://static.crates.io/crates/sha1/sha1-0.10.6.crate \
https://static.crates.io/crates/sha2/sha2-0.10.8.crate \
- https://static.crates.io/crates/sha2/sha2-1.21.0.crate \
https://static.crates.io/crates/shadowsocks-crypto/shadowsocks-crypto-0.5.5.crate \
- https://static.crates.io/crates/shadowsocks-crypto/shadowsocks-crypto-1.21.2.crate \
- https://static.crates.io/crates/shadowsocks-crypto/shadowsocks-crypto-1.21.2.crate \
https://static.crates.io/crates/sharded-slab/sharded-slab-0.1.7.crate \
https://static.crates.io/crates/shlex/shlex-1.3.0.crate \
https://static.crates.io/crates/signal-hook-registry/signal-hook-registry-1.4.2.crate \
39e3168b0ff2d77bcca05882310b2a06 \
d7602381c0bc21d10603cc940a837b06 \
289b776935f2184c6ba2974877285013 \
- 3172cc7eed7041f89d35715a93cac031 \
cbac6a37ea78204d483d4d224de6ab90 \
- 7558b0d6a956faf7f1644b6fc7f53755 \
- c2fdaa2514e053b8a3180b528724696e \
96261f3cee18842060fd64d618e056d8 \
6c623a8eed8450399ec323a72e96855c \
a77d5770902a4260009320daafd1fff2 \