|
puterboy has asked for the
wisdom of the Perl Monks concerning the following question:
I would like to copy files preserving attributes (something like cp -cdpP) within perl rather than using a system call to *nix 'cp'.
Now from the documentation of File::Copy, it seems that this module won't do that for me at least on *nix since there is no syscopy routine.
I also saw an old thread (Circa 2003) saying that since the potential attributes to be preserved are not well-defined across systems (and may change in the future), this functionality has not been implemented in CPAN.
So, I ask is that still true?
Is there any (easy) way other than forking a syscall to preserve the following attributes:
timestamps
ownership
permissions
SELinux
Other ACL/extended attributes
Re: Copy preserving attributes by thunders (Curate) on Nov 02, 2009 at 17:32 UTC |
Which version of Perl and File::Copy are you using? In CPAN File::Copy does indeed provided a syscopy.
Update: sorry read the docs and you are correct. On UNIX syscopy is just an alias to File::Copy::copy()
Here's a thread with the same essential question.
| [reply] |
|
Yes - that was exactly the thread from 2003 that I was alluding to. But since it has been 6+ years, I was wondering whether there were any new approaches or solutions... One can always hope...
| [reply] |
Re: Copy preserving attributes by stefbv (Sexton) on Nov 02, 2009 at 18:00 UTC |
Maybe Sysadm::Install can do the job. | [reply] |
Re: Copy preserving attributes by ikegami (Saint) on Nov 02, 2009 at 18:10 UTC |
I would like to copy files preserving attributes (something like cp -cdpP) within perl rather than using a system call to *nix 'cp'.
Calling cp is your best option. It can be done safely with multi-arg system
my $rv = system('cp', '-cdpP', ...);
$rv == -1 and die("Can't execute cp: $!\n");
$rv & 0x7F and die("cp died from signal ", ($rv & 0x7F), "\n");
$rv >> 8 and die("Error ", ($rv >> 8), "from cp\n");
| [reply] [d/l] [select] |
Re: Copy preserving attributes by keszler (Pilgrim) on Nov 02, 2009 at 18:24 UTC |
| [reply] |
|
| [reply] |
|
| [reply] |
|
Re: Copy preserving attributes by zentara (Chancellor) on Nov 02, 2009 at 18:58 UTC |
| [reply] |
Re: Copy preserving attributes by djp (Friar) on Nov 03, 2009 at 09:41 UTC |
I've used File-Rsync with the --archive option set to achieve this. Not the most elegant solution, but it will do what you want. | [reply] |
|
Interesting idea, but I imagine that calling rsync even if coded all in Perl will be *slower* than a 'cp' system call.
| [reply] |
Back to
Seekers of Perl Wisdom
|