develooper Front page | perl.perl5.porters | Postings from October 2005

Re: Inconsistent behaviour when removing files on Cygwin

Thread Previous | Thread Next
From:
Steve Peters
Date:
October 26, 2005 10:40
Subject:
Re: Inconsistent behaviour when removing files on Cygwin
Message ID:
20051026174003.GA19696@mccoy.peters.homeunix.org
On Wed, Oct 26, 2005 at 05:28:30PM +0200, S├ębastien Aperghis-Tramoni wrote:
> Hello,
> 
> While correcting a bug in Net::Pcap Makefile.PL with a Windows developer,
> we stumbled upon the strange behaviour of the unlink() function under
> Cygwin. It looks like it tries to emulates the Unix behaviour but fails
> to achieve it.
> 
>     # create a file
>     my $file = 'test.txt';
>     open(FILE, '>', $file) or die "can't write '$file': $!\n";
> 
>     # then try to unlink it
>     unlink($file) or warn "can't unlink '$file': $!\n";
> 
>     # check whether it's still present
>     print "'$file' ", (-f $file ? "does" : "doesn't"),
>       " exist on the filesystem\n";
> 
>     # check whether it's listed
>     opendir(DIR, '.');
>     print "in dir: ", (grep {/$file/} readdir(DIR)), $/;
>     closedir(DIR);
> 
>     # close the file and check again
>     close(FILE);
>     print "'$file' ", (-f $file ? "does" : "doesn't"),
>       " exist on the filesystem\n";
> 
>     opendir(DIR, '.');
>     print "in dir: ", (grep {/$file/} readdir(DIR)), $/;
>     closedir(DIR);
> 
<snip>

I've seen similar problems on Win32 before, but it has nothing to do with 
Perl.  The Win32 filesystems do not necessarily update directory entries
immediately.  The resulting symptom is that you are unable to delete a file
that had recently been created.  Once upon a time I had a link to the
explanation for the problem, but that seems to have been lost.
For my solution, I used File::Temp.  See 
http://rt.cpan.org/NoAuth/Bug.html?id=13574 for my solution to the problem.

Steve Peters
steve@fisharerojo.org

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About