in reply to cp -p in perl?

Is there a perl module or a perl builtin that will perform a file copy but preserve the permissions of the copied file?
Unless something has changed recently, the most cited module for copying files, File::Copy doesn't do it. In fact, it doesn't even mimic the default cp behaviour, dropping permissions when you least expect it.

My advice for copying files is to use system cp => @files, $destination. cp is far more useful than File::Copy::copy that a potential loss in portability (but bare in mind that cp has been ported outside of Unix systems) is well worth the gain.

Abigail

Replies are listed 'Best First'.
Re: Re: cp -p in perl?
by BuddhaNature (Beadle) on Apr 20, 2004 at 23:37 UTC
    It looks like (so far) the best way to do this is to do all your work on a tempfile ( I like File::Temp myself) version of the file you want to copy and then do your chmod and/or chown on the tempfile and then use rename(). This seems to work correctly.
      That doesn't sound like a good idea at all to me. First of all, we're talking about just copying a file, not about any modification. Secondly, using chmod/chown is a lot more work than just using cp. But most importantly, rename will not rename from one device to another.

      Abigail