Accept directories whose name contains a period (#97) - #107
Open
youdie006 wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #97.
Problem
createTarball/createZipArchive(and theaddDirprocs they call) decide whether their argument is a directory by inspecting the filename's extension: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.dare rejected and no archive is created.Fix
Check the filesystem with
dirExistsinstead of guessing from the name (bothtarballs_v1.nimandziparchives_v1.nim;std/osis already imported). This accepts dotted directory names and still rejects files and nonexistent paths.Test
Added
tests/test_issue_97.nim(registered intests/all.nim): it creates a directory namedzippy_dotted.d, archives it withcreateTarballandcreateZipArchive, and round-trips the contents; it also asserts a real file is still rejected withZippyError. Red-green verified withnim c -r: before the fixcreateTarballraises... appears to be a file?on the dotted directory; after, both archive and extract succeed. The fulltests/all.nimsuite still passes.