Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

File::Copy and moving directories across volumes

by creamygoodness (Curate)
on Dec 05, 2008 at 01:12 UTC ( [id://728153]=perlquestion: print w/replies, xml ) Need Help??

creamygoodness has asked for the wisdom of the Perl Monks concerning the following question:

Greets,

File::Copy's move() command fails when trying to move a directory from one volume to another. However, the system mv command succeeds.

-bash-3.1$ pwd /home/marvin -bash-3.1$ ls /usr1/stuff | grep foo -bash-3.1$ mkdir foo -bash-3.1$ perl -MFile::Copy -e 'move("foo", "/usr1/stuff/foo") or die + $!' Is a directory at -e line 1. -bash-3.1$ mv foo/ /usr1/stuff/foo -bash-3.1$ ls /usr1/stuff | grep foo foo -bash-3.1$

Is this expected behavior?

--
Marvin Humphrey

Replies are listed 'Best First'.
Re: File::Copy and moving directories across volumes (complex)
by tye (Sage) on Dec 05, 2008 at 02:00 UTC

    Copying[moving] a directory from one volume to another would require traversing a whole directory tree and copying each file and creating copies of each directory [and also deleting these after they are copied]. It is a huge operation in comparison to the rest of the things that File::Copy does.

    So I'm not at all surprised that this feature isn't included. Perhaps you don't remember that 'mv' in Unix didn't even handle this case either for many years (we used tar or cpio to do it).

    Checking the dependencies for File::Copy I don't see File::Find or some equivalent listed so I'm pretty sure this (significantly more complex case) is not implemented by it.

    So I'd actually expect this to be implemented in a separate module that likely uses File::Copy and perhaps File::Path. I don't know if such a module has been written but it seems likely somebody would have done that by now.

    - tye        

Re: File::Copy and moving directories across volumes
by oko1 (Deacon) on Dec 05, 2008 at 01:44 UTC

    According to the docs, it's... not really covered.

    If the destination already exists and is a directory, and the sour +ce is not a directory, then the source file will be renamed into the directory specified by the destination.

    There's a bunch of comments in the module code itself that deals with a broken NFS mount - which at least implies that it should work for moving between mounted dirs. According to my own tests, it does not:

    ben@Tyr:/tmp$ mount|grep home /home on /chroot/home type none (rw,bind) ben@Tyr:/tmp$ mkdir test; perl -MFile::Copy -we'move("test", "/chroot/ +home/test") or die "test: $!\n"' mkdir: cannot create directory `test': File exists test: Is a directory

    It also fails - in a rather ugly manner - when you try to move an existing directory into another existing directory:

    ben@Tyr:/tmp$ mkdir test test1; perl -MFile::Copy -we'move("test", "te +st1") or die "$!\n"'; ls -lR test test1 ls: cannot access test: No such file or directory test1: total 0

    In other words, "test" just got wiped out. Not moved, or copied, or even died with an error message - just wiped out. I'd suggest filing a bug report.


    --
    Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf
Re: File::Copy and moving directories across volumes
by mvaline (Friar) on Dec 05, 2008 at 04:12 UTC
    I believe File-xcopy will allow you to copy between volumes.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://728153]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found