# HG changeset patch # User Franz Glasner # Date 1650525381 -7200 # Node ID 42419f57eda983183f626d9e9e047f73847d4b0c # Parent 72684020f2f3fd7215c10eaef54cfc854085fc2a Allow to control the use of mmap from the command-line diff -r 72684020f2f3 -r 42419f57eda9 cutils/shasum.py --- a/cutils/shasum.py Thu Apr 21 01:20:35 2022 +0200 +++ b/cutils/shasum.py Thu Apr 21 09:16:21 2022 +0200 @@ -86,6 +86,14 @@ help='Allow FreeBSD "distinfo" formatted checklists: ignore SIZE and TIMESTAMP lines.') aparser.add_argument( + "--mmap", action="store_true", dest="mmap", default=None, + help="""Use mmap if available. Default is to determine automatically + from the filesize.""") + aparser.add_argument( + "--no-mmap", action="store_false", dest="mmap", default=None, + help="Dont use mmap.") + + aparser.add_argument( "--reverse", "-r", action="store_false", dest="bsd", default=False, help="Explicitely select normal coreutils style output (to be option compatible with BSD style commands and :command:`openssl dgst -r`)") aparser.add_argument( @@ -167,7 +175,8 @@ else: for fn in opts.files: out(opts.dest or sys.stdout, - compute_digest_file(opts.algorithm[0], fn), + compute_digest_file(opts.algorithm[0], fn, + use_mmap=opts.mmap), fn, opts.algorithm[1], True, @@ -247,7 +256,8 @@ exit_code = 1 else: tag, algo, cl_filename, cl_digest = pl - computed_digest = compute_digest_file(algo, fn) + computed_digest = compute_digest_file(algo, fn, + use_mmap=opts.mmap) if compare_digests_equal(computed_digest, cl_digest, algo): res = "OK" else: @@ -303,7 +313,7 @@ assert opts.allow_distinfo return (None, None, tag) try: - d = compute_digest_file(algo, fn) + d = compute_digest_file(algo, fn, use_mmap=opts.mmap) if compare_digests_equal(d, digest, algo): return ("ok", fn, tag) else: