Mercurial > hgrepos > Python > apps > py-cutils
changeset 105:b0631f320efd
Implement "--follow-symlinks" to allow to control whether to follow directory symlinks
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 29 May 2022 01:06:25 +0200 |
| parents | 08fd0609fdd4 |
| children | 5fe6f63f0be7 |
| files | cutils/shasum.py |
| diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/cutils/shasum.py Thu May 26 23:14:38 2022 +0200 +++ b/cutils/shasum.py Sun May 29 01:06:25 2022 +0200 @@ -86,6 +86,10 @@ help='Allow FreeBSD "distinfo" formatted checklists: ignore SIZE and TIMESTAMP lines.') aparser.add_argument( + "--follow-symlinks", action="store_true", dest="follow_symlinks", + help="""Also follow symlinks that resolve to directories. Only effective if `--recurse` is activated.""") + + aparser.add_argument( "--mmap", action="store_true", dest="mmap", default=None, help="""Use mmap if available. Default is to determine automatically from the filesize.""") @@ -95,7 +99,7 @@ aparser.add_argument( "--recurse", action="store_true", - help="Recurse into sub-directories while interpreting every FILE as a directory") + help="Recurse into sub-directories while interpreting every FILE as a directory.") aparser.add_argument( "--reverse", "-r", action="store_false", dest="bsd", default=False, @@ -174,7 +178,8 @@ raise OSError(errno.ENOTDIR, "not a directory", dn) else: raise OSError(errno.ENOENT, "directory does not exist", dn) - for dirpath, dirnames, dirfiles in os.walk(dn, followlinks=True): + for dirpath, dirnames, dirfiles in os.walk( + dn, followlinks=opts.follow_symlinks): for fn in dirfiles: path = os.path.join(dirpath, fn) out(opts.dest or sys.stdout,
