sapling/tests/truncate.py
Mark Thomas 1ac1128def truncate: add truncate implementation
Summary:
The `truncate` tool isn't availble on OSX, so include our own in the test
suite.

Reviewed By: DurhamG

Differential Revision: D12815613

fbshipit-source-id: 510b2936f07c5193671baaeaec6620872c3ec982
2018-10-27 10:59:21 -07:00

25 lines
594 B
Python
Executable File

#!/usr/bin/env python
import argparse
if __name__ == "__main__":
ap = argparse.ArgumentParser(usage="%(prog)s [options] file...")
ap.add_argument(
"-s",
"--size",
type=int,
default=0,
help="size in bytes to truncate to",
metavar="BYTES",
)
ap.add_argument("file", nargs="+", help="file to truncate", metavar="FILE")
args = ap.parse_args()
size = args.size
if size < 0:
ap.error("size cannot be negative")
for filename in args.file:
with open(filename, "a+b") as f:
f.truncate(size)