I expect copied files to have the same flags as the original file
I've been copying some executable files and noticed the permission flags are getting dropped on a copy. It would be nice if the library defaulted to maintaining file flags.
My workaround:
(defn copy-permissions [from to]
(when (fs/executable? from)
(fs/chmod "+x" to))
(when (fs/writeable? from)
(fs/chmod "+w" to))
(when (fs/readable? from)
(fs/chmod "+r" to)))
(defonce _|HACK_TOWN
(alter-var-root #'fs/copy
(fn [old]
(fn [from to]
(old from to)
(copy-permissions from to)))))
Happy to turn it into a PR if others are in agreement about the change in functionality.
Not sure how to proceed with this, as I don't want to change the semantics of this fn. It would be possible to add a second arity which accepted an options map?
I'm working on a modernized version of fs here, which reflects the usage of Java nio:
https://github.com/babashka/fs/blob/9bddc8428f344f21f1c2a306314e7a2222f37205/src/babashka/fs.clj#L143
It takes the following options:
{:keys [:replace-existing
:copy-attributes
:nofollow-links
:recursive]}
which are named after the Java 7 options.