fs icon indicating copy to clipboard operation
fs copied to clipboard

I expect copied files to have the same flags as the original file

Open RutledgePaulV opened this issue 6 years ago • 2 comments

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.

RutledgePaulV avatar Oct 19 '19 18:10 RutledgePaulV

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?

slipset avatar Dec 30 '20 10:12 slipset

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.

borkdude avatar Dec 30 '20 10:12 borkdude