Skip to content

Accept directories whose name contains a period (#97) - #107

Open
youdie006 wants to merge 1 commit into
guzba:masterfrom
youdie006:fix/97-adddir-dotted-directory
Open

Accept directories whose name contains a period (#97)#107
youdie006 wants to merge 1 commit into
guzba:masterfrom
youdie006:fix/97-adddir-dotted-directory

Conversation

@youdie006

Copy link
Copy Markdown

Fixes #97.

Problem

createTarball / createZipArchive (and the addDir procs they call) decide whether their argument is a directory by inspecting the filename's extension:

if splitFile(dir).ext.len > 0:
  raise newException(ZippyError, "Error adding dir " & dir & " ... appears to be a file?")

So any real directory whose name contains a period is refused. splitFile("/etc/cron.d").ext == ".d", so common directories like /etc/cron.d, /etc/logrotate.d, network.d are rejected and no archive is created.

Fix

Check the filesystem with dirExists instead of guessing from the name (both tarballs_v1.nim and ziparchives_v1.nim; std/os is already imported). This accepts dotted directory names and still rejects files and nonexistent paths.

Test

Added tests/test_issue_97.nim (registered in tests/all.nim): it creates a directory named zippy_dotted.d, archives it with createTarball and createZipArchive, and round-trips the contents; it also asserts a real file is still rejected with ZippyError. Red-green verified with nim c -r: before the fix createTarball raises ... appears to be a file? on the dotted directory; after, both archive and extract succeed. The full tests/all.nim suite still passes.

addDir decided whether its argument was a directory by inspecting the
filename extension (splitFile(dir).ext.len > 0), so a real directory
whose name contains a period (e.g. /etc/cron.d) was rejected as "appears
to be a file?" and no archive was created; createTarball and
createZipArchive therefore failed on valid input.

Check the filesystem with dirExists instead. This accepts dotted
directory names and still rejects files and nonexistent paths.

Fixes guzba#97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot create archive of a directory with a period in its name

1 participant