Search code examples
rubyfile-permissionscp

ruby cp ignores access permissions if not pointing to specific file


I have following code:

def post_install

  cp Dir[lib/"directory/defaultconfigs/*"], etc/"directory"

While the snippet above ignores the access permissions,

cp Dir[lib/"directory/defaultconfigs/testfile.d"], etc/"directory"

does not ignore it. How do I get the first command to copy all files including their permissions?


Solution

  • I solved it myself, with cp_r you can add the preserve option which keeps permissions as-is.

    The line cp_r Dir[lib/"directory/defaultconfigs/*"], etc/"directory", :preserve => true works for me.