Skip to content

Commit

Permalink
Improved --checksum filename escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
haukex committed May 31, 2024
1 parent b9fd552 commit e3f8275
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
Changelog for unzipwalk
=======================

1.2.1 - Fri, May 31 2024
------------------------

- Improved escaping of filenames with `--checksum` CLI option.

1.2.0 - Fri, May 31 2024
------------------------

`commit b9fd55222886dd3e074ea374dbd901f9024ee497`

- Added `matcher` argument to `unzipwalk()` and corresponding `--exclude` CLI option.

1.1.0 - Fri, May 31 2024
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "unzipwalk"
description = "Recursively walk into directories and archives"
version = "1.2.0"
version = "1.2.1"
authors = [ { name="Hauke D", email="haukex@zero-g.net" } ]
readme = "README.md"
requires-python = ">=3.9"
Expand Down
20 changes: 11 additions & 9 deletions unzipwalk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,17 +343,19 @@ def matcher(paths :Sequence[PurePath]) -> bool:
return not any( fnmatch(paths[-1].name, pat) for pat in args.exclude )
for result in unzipwalk( args.paths if args.paths else Path(), matcher=matcher ):
names = tuple( str(n) for n in result.names )
if (args.dump or args.checksum) and result.typ==FileType.FILE:
assert result.hnd is not None # make type checker happy; we know this is true because we checked it's a file
if args.checksum:
if args.checksum:
name = names[0] if len(names)==1 and not names[0].startswith('(') and '\n' not in names[0] and '\r' not in names[0] else repr(names)
if result.typ==FileType.FILE:
assert result.hnd is not None
h = hashlib.new(args.checksum)
h.update(result.hnd.read())
print(f"{h.hexdigest()} *{names[0] if len(names)==1 else repr(names)}")
else:
print(f"{h.hexdigest()} *{name}")
elif args.all_files:
print(f"# {result.typ.name} {name}")
else:
if result.typ==FileType.FILE and args.dump:
assert result.hnd is not None
print(f"{result.typ.name} {names!r} {result.hnd.read()!r}")
elif result.typ==FileType.FILE or args.all_files:
if args.checksum:
print(f"# {result.typ.name} {names[0] if len(names)==1 else repr(names)}")
else:
elif result.typ==FileType.FILE or args.all_files:
print(f"{result.typ.name} {names!r}")
parser.exit(0)

0 comments on commit e3f8275

Please sign in to comment.