summaryrefslogtreecommitdiffstats
path: root/debian/prune-checksums
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:05 +0000
commit217d9223a5aa75daf9f286fd1fc06dae379b5dbc (patch)
treeb43bedae234ad56894a82934ee57e3619f3374d5 /debian/prune-checksums
parentAdding upstream version 1.64.0+dfsg1. (diff)
downloadrustc-217d9223a5aa75daf9f286fd1fc06dae379b5dbc.tar.xz
rustc-217d9223a5aa75daf9f286fd1fc06dae379b5dbc.zip
Adding debian version 1.64.0+dfsg1-1.debian/1.64.0+dfsg1-1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/prune-checksums')
-rwxr-xr-xdebian/prune-checksums47
1 files changed, 47 insertions, 0 deletions
diff --git a/debian/prune-checksums b/debian/prune-checksums
new file mode 100755
index 000000000..0c895cff4
--- /dev/null
+++ b/debian/prune-checksums
@@ -0,0 +1,47 @@
+#!/usr/bin/python3
+# Copyright: 2015-2017 The Debian Project
+# License: MIT or Apache-2.0
+#
+# Helper to remove removed-files from .cargo-checksum
+# TODO: rewrite to perl and add to dh-cargo, maybe?
+
+from collections import OrderedDict
+import argparse
+import json
+import os
+import sys
+
+def prune_keep(cfile):
+ with open(cfile) as fp:
+ sums = json.load(fp, object_pairs_hook=OrderedDict)
+
+ oldfiles = sums["files"]
+ newfiles = OrderedDict([entry for entry in oldfiles.items() if os.path.exists(entry[0])])
+ sums["files"] = newfiles
+
+ if len(oldfiles) == len(newfiles):
+ return
+
+ with open(cfile, "w") as fp:
+ json.dump(sums, fp, separators=(',', ':'))
+
+def prune(cfile):
+ with open(cfile, "r+") as fp:
+ sums = json.load(fp, object_pairs_hook=OrderedDict)
+ sums["files"] = {}
+ fp.seek(0)
+ json.dump(sums, fp, separators=(',', ':'))
+ fp.truncate()
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-k", "--keep", action="store_true", help="keep "
+ "checksums of files that still exist, and assume they haven't changed.")
+ parser.add_argument('crates', nargs=argparse.REMAINDER,
+ help="crates whose checksums to prune. (default: ./)")
+ args = parser.parse_args(sys.argv[1:])
+ crates = args.crates or ["."]
+ f = prune_keep if args.keep else prune
+ for c in crates:
+ cfile = os.path.join(c, ".cargo-checksum.json") if os.path.isdir(c) else c
+ f(cfile)