File::Path::remove_tree not working

Discussion in 'Perl Misc' started by Allan Herriman, Sep 18, 2012.

  1. Hi,

    I have a script that creates a temporary directory using

    my $tempdir = tempdir( CLEANUP => 1 );

    Some readonly files are then created in that directory. All are closed
    before the script finishes.

    On my development machine (Activestate Perl 5.16.0 on Windows 7) it
    worked fine: the directory was removed after the script finished.

    On the deployment machines (Cygwin Perl 5.10.1 on Windows Server 2003) it
    doesn't remove the directory or any of the files in the directory.



    I then added the following line at the end of the script:

    remove_tree($tempdir, { safe => 0 });

    but that didn't fix anything.

    It didn't write anything to STDERR, which I think indicates it didn't
    encounter detectable error conditions.

    I'm using -w and strict.

    I can manually delete the directory in windows explorer without any
    warnings or prompts, so it doesn't appear to be a permission problem.


    What do I do next?


    Thanks,
    Allan
    Allan Herriman, Sep 18, 2012
    #1
    1. Advertising

  2. Allan Herriman

    ilovelinux Guest

    > my $tempdir = tempdir( CLEANUP => 1 );
    > remove_tree($tempdir, { safe => 0 });


    Smells like somethnig weird in the Cygwin layer. I once encountered a similar error: the Cygwin perl script removed some files but they stayed visiblefrom an Explorer view in another window, until the perl script finished: only then the removed files disappeared.

    Did you try removing the files by hand-crafted code? Something like this:

    for (glob("$tempdir/*")) {
    print "removing $_: ";
    if (unlink($_)) {
    print "OK\n";
    } else {
    print "ERR ($!)\n";
    }
    }
    ilovelinux, Sep 20, 2012
    #2
    1. Advertising

  3. On Wed, 19 Sep 2012 23:27:55 -0700, ilovelinux wrote:

    >> my $tempdir = tempdir( CLEANUP => 1 );
    >> remove_tree($tempdir, { safe => 0 });

    >
    > Smells like somethnig weird in the Cygwin layer. I once encountered a
    > similar error: the Cygwin perl script removed some files but they stayed
    > visible from an Explorer view in another window, until the perl script
    > finished: only then the removed files disappeared.
    >
    > Did you try removing the files by hand-crafted code? Something like
    > this:
    >
    > for (glob("$tempdir/*")) {
    > print "removing $_: ";
    > if (unlink($_)) {
    > print "OK\n";
    > } else {
    > print "ERR ($!)\n";
    > }
    > }



    I even tried rm -rf and that didn't work, which I found rather surprising.

    > Smells like somethnig weird in the Cygwin layer.


    It turns out that in Cygwin paths starting with /tmp/ get magically
    redirected to c:/cygwin/tmp/
    I cannot imagine a universe where that would be a good idea, but
    apparently the Cygwin authors thought it was.

    tempdir returns /tmp/something, and this gets interpreted as
    c:/tmp/something by some parts of my script and as
    c:/cygwin/tmp/something by other parts of my script (including tempdir
    itself).

    tempdir does in fact clean up its directory, but not the directory I
    thought it was using.

    My ugly, non-portable and fragile workaround is to chdir to c: then
    prepend the temp directory name with c: before I use it.

    Regards,
    Allan
    Allan Herriman, Sep 21, 2012
    #3
  4. Allan Herriman

    ilovelinux Guest

    > It turns out that in Cygwin paths starting with /tmp/ get magically
    > redirected to c:/cygwin/tmp/


    Not if you mount it yourself. My /etc/fstab (Cygwin) contains

    c:/temp /tmp some_fs binary 0 0
    d:/Users /home some_fs binary 0 0
    none / cygdrive binary,posix=0,user 0 0

    The top line forces all accesses of /tmp to use the c:/temp directory.

    HTH
    ilovelinux, Sep 21, 2012
    #4
  5. Allan Herriman

    Kaz Kylheku Guest

    On 2012-09-21, Ben Morrow <> wrote:
    >
    > Quoth Allan Herriman <>:
    >>
    >> It turns out that in Cygwin paths starting with /tmp/ get magically
    >> redirected to c:/cygwin/tmp/
    >> I cannot imagine a universe where that would be a good idea, but
    >> apparently the Cygwin authors thought it was.

    >
    > This is usual Cygwin behaviour: in fact, it's one of the main reasons to
    > use Cygwin in the first place.


    One of the main reasons for using Cygwin is where it sticks /tmp?
    Kaz Kylheku, Sep 21, 2012
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Magnus Blomberg

    Space in path not working with Images

    Magnus Blomberg, Sep 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    599
    Kirby Turner
    Sep 3, 2004
  2. Replies:
    0
    Views:
    813
  3. Replies:
    1
    Views:
    582
    Oliver Wong
    Jul 13, 2006
  4. Replies:
    9
    Views:
    489
    Juan T. Llibre
    Dec 7, 2006
  5. \A_Michigan_User\

    Various path/path/files.asp all #include this 1 file

    \A_Michigan_User\, Jul 10, 2005, in forum: ASP General
    Replies:
    1
    Views:
    230
    Jeff Cochran
    Jul 10, 2005
Loading...

Share This Page