sparseutils

utilities for interacting with sparse files
Log | Files | Refs | README | LICENSE

commit a1fa69eaf52b4b1ca55577ad0e7c9f397ac7089d
parent 374a7f515a24541cc7cc0f75deb88e8a58b844d0
Author: Richard Ipsum <richardipsum@fastmail.co.uk>
Date:   Sun,  2 Apr 2017 12:58:22 +0100

sparsemap: Check for errors

Diffstat:
Msparseutils/sparsemap.py | 16+++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/sparseutils/sparsemap.py b/sparseutils/sparsemap.py @@ -19,6 +19,7 @@ import sys import os +import stat import errno def sparsemap(fd): @@ -61,7 +62,20 @@ def main(): print('usage: {} FILE'.format(sys.argv[0]), file=sys.stderr) sys.exit(1) - fd = os.open(sys.argv[1], os.O_RDONLY) + path = sys.argv[1] + + try: + mode = os.stat(path).st_mode + except os.error as e: + print("{}: Couldn't open `{}': {}".format(sys.argv[0], path, e.strerror)) + sys.exit(1) + + if not stat.S_ISREG(mode): + print("{}: error: `{}' is not a regular file".format(sys.argv[0], path), + file=sys.stderr) + sys.exit(1) + + fd = os.open(path, os.O_RDONLY) sparsemap(fd) os.close(fd)