Skip to content

Commit

Permalink
[#35] Unzip: entry in dir can come before dir in zip entries
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 12, 2021
1 parent 4215675 commit 21eb065
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ gh-pages/

# lsp
.lsp/

!test-resources/bencode-1.1.0.jar
8 changes: 5 additions & 3 deletions src/babashka/fs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,9 @@
new-path (.resolve output-path entry-name)]
(if (.isDirectory entry)
(create-dirs new-path)
(Files/copy ^java.io.InputStream zis
new-path
cp-opts)))
(do
(create-dirs (parent new-path))
(Files/copy ^java.io.InputStream zis
new-path
cp-opts))))
(recur))))))))
Binary file added test-resources/bencode-1.1.0.jar
Binary file not shown.
10 changes: 8 additions & 2 deletions test/babashka/fs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@
(.putNextEntry zos entry))
(io/copy fis zos)))

(deftest zip-test
(deftest unzip-test
(let [td (fs/create-temp-dir)
td-out (fs/path td "out")
zip-file (fs/path td "foo.zip")
Expand All @@ -410,4 +410,10 @@
(is (thrown? java.nio.file.FileAlreadyExistsException (fs/unzip zip-file td-out)))
(testing "no exception when replacing existing"
(is (do (fs/unzip zip-file td-out {:replace-existing true})
true)))))
true))))
(testing "Entry within directory can become before directory"
(let [td (fs/create-temp-dir)
td-out (fs/path td "out")
zip-file (fs/path "test-resources" "bencode-1.1.0.jar")]
(fs/unzip zip-file td-out)
(is (fs/exists? (fs/file td-out "bencode" "core.clj"))))))

0 comments on commit 21eb065

Please sign in to comment.