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

What is the best way to move a directory to a mounted filesystem?

by wenD (Beadle)
on Nov 29, 2006 at 17:56 UTC ( #586766=perlquestion: print w/replies, xml ) Need Help??
wenD has asked for the wisdom of the Perl Monks concerning the following question:

I get an error when trying to use File::Copy to move a directory to a mounted section of the filesystem.

---------------------------- use File::Copy; my $source_dir = '/home/my/this_dir'; my $destination_dir = '/nfsmount/elsewhere/this_dir'; move("$source_dir", "$destination_dir"); if ( $! ) { # Prints 'Is a directory' (and the move doesn't happen). print $!; } ----------------------------

Is File::Copy the wrong thing to use for this? Or am I just doing something wrong?

20061201 Janitored by Corion: Changed formatting to use code tags instead of PRE tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: What is the best way to move a directory to a mounted filesystem?
by ikegami (Pope) on Nov 29, 2006 at 18:03 UTC

    File::Copy can rename directories, but it can't copy them, so it can't be used to move one to another filesystem.

    It's probably simpler to use system to execute a tool provided by your OS.

    By the way, no need to put your variables in double quotes.

    Update: How about:

    my $cp_rv = system('cp', '-rp', $src, $dst); if ($cp_rv) { if ($cp_rv == -1) { die("Unable to launch 'cp': $!\n"); } else { system('rm', '-rf', $dst); die("Unable to copy \"$src\" directory. \"cp\" returned $?\n"); } } system('rm', '-rf', $src);
Re: What is the best way to move a directory to a mounted filesystem?
by derby (Abbot) on Nov 29, 2006 at 18:24 UTC

    You don't give any platform specs but I would imagine the underlying guts of File::Copy do not support directory moving for your platform. Looking at the docs, it appears to only support file to file and file to directory moving. There's nothing magical about File::Copy - you could always just single step through the debugger to catch where you're failing.

    -derby

      Thanks for your replies. A few more details I should have included...

      The platform is Linux.
      Permissions are okay.
      I can get File::Copy to move a directory from one place to another as long as it's on the same filesystem.
      ---------------------------- use File::Copy; my $source_dir = '/home/my/this_dir'; my $destination_dir = '/usr/local/elsewhere/this_dir'; # This works fine. move($source_dir, $destination_dir); ----------------------------
        In your OP the destination path is /nfsmount/elsewhere/this_dir implying that the filesystem id from a remote server. Have you checked whether the filesystem has been shared on that server as read-only. I know this can throw a spanner in the works under Solaris.

        Just a thought,

        JohnGG

Re: What is the best way to move a directory to a mounted filesystem?
by blue_cowdawg (Monsignor) on Nov 29, 2006 at 21:47 UTC
        Is File::Copy the wrong thing to use for this? Or am I just doing something wrong?

    Ah Dear Esteemed Monk,
    If you'd have added a bit of code such as:

    #!/usr/bin/perl use File::Copy; move('foobar','/mnt/peter/tmp/')or die $!;
    You would have recieved a great big hint:
    Is a directory at foo.pl line 4.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

      Uhh ... doesn't the OP do the same thing (he even noted the error message in a comment).

      -derby
            doesn't the OP do the same thing

        Senility must be setting in for me. I somehow missed that.

        At any rate, I experimented around with this and found that it just plain won't work. Not sure why, but it won't work.

        If I were to attempt to do what the OP were doing I'd probably use some form of File::Find foo and remove the original afterwards.


        Peter L. Berghold -- Unix Professional
        Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: What is the best way to move a directory to a mounted filesystem?
by Fengor (Pilgrim) on Nov 29, 2006 at 18:17 UTC
    I assume write priviliges for the directory are given?

    --
    "WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
    -- Terry Pratchett, "Reaper Man"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://586766]
Approved by ikegami
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2017-12-16 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (454 votes). Check out past polls.

    Notices?