Skip to content

Commit

Permalink
Fix #48: support input-stream in fs/copy (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored May 11, 2023
1 parent 7a97ff9 commit 4eded14
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ For a list of breaking changes, check [here](#breaking-changes).

Babashka [fs](https://github.com/babashka/fs): file system utility library for Clojure

## Unreleased
## v0.4.18 (2023-05-11)

- [#48](https://github.com/babashka/fs/issues/48): support input-stream in `fs/copy`
- [#91](https://github.com/babashka/fs/issues/91): add 1-arity to `xdg-*-home` to get subfolder of base directory ([@eval](https://github.com/eval))
- [#94](https://github.com/babashka/fs/issues/94): updates to `which`: add `:paths` `opt`, allow absolute paths for `program` ([@lread](https://github.com/lread))

Expand Down
20 changes: 11 additions & 9 deletions src/babashka/fs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,18 @@
* `:copy-attributes`
* `:nofollow-links` (used to determine to copy symbolic link itself or not)."
([src dest] (copy src dest nil))
([src dest {:keys [:replace-existing
:copy-attributes
:nofollow-links]}]
([src dest {:keys [replace-existing
copy-attributes
nofollow-links]}]
(let [copy-options (->copy-opts replace-existing copy-attributes false nofollow-links)
dest (as-path dest)]
(if (directory-simple? dest)
(Files/copy (as-path src) (path dest (file-name src))
copy-options)
(Files/copy (as-path src) dest
copy-options)))))
dest (as-path dest)
dest (if (directory-simple? dest)
(path dest (file-name src))
dest)
input-stream? (instance? java.io.InputStream src)]
(if input-stream?
(Files/copy ^java.io.InputStream src dest copy-options)
(Files/copy (as-path src) dest copy-options)))))

(defn posix->str
"Converts a set of PosixFilePermission to a string."
Expand Down
7 changes: 6 additions & 1 deletion test/babashka/fs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@
(is (not (fs/exists? dest-file)))
(testing "copying into dir"
(fs/copy src-file dest-dir)
(is (fs/exists? dest-file)))))
(is (fs/exists? dest-file)))
(testing "copying input-stream"
(fs/delete dest-file)
(fs/copy (io/input-stream (fs/file src-file)) dest-file)
(is (fs/exists? dest-file))
(is (= (slurp (fs/file src-file)) (slurp (fs/file dest-file)))))))

(deftest copy-tree-test
(let [tmp-dir (temp-dir)]
Expand Down

0 comments on commit 4eded14

Please sign in to comment.