Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Path-Class CPAN distribution.

Maintainer(s)' notes

I prefer that bugs & patches are filed on GitHub rather than on RT: https://github.com/kenahoo/Path-Class/issues. Thanks.

Report information
The Basics
Id: 83880
Status: open
Priority: 0/
Queue: Path-Class

People
Owner: Nobody in particular
Requestors: ediap [...] wp.pl
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [Path::Class:File] slurp() method does not close file handle prior returning
Date: Mon, 11 Mar 2013 14:48:46 +0100
To: bug-Path-Class [...] rt.cpan.org
From: Adam Piątyszek <ediap [...] wp.pl>
Hi, It seems that the slurp() method of Path::Class::File does not close the file handle created with $self->open($iomode). This causes problems with removal of a directory containing the just slurped file with Path::Class::Dir->rmtree(). A simple fix should be to just add: "$fh->close;" after: my @data = <$fh>; and chomp( my @data = <$fh> ); lines of the slurp() method. Thanks, /Adam
Thanks Adam. By opening $fh the way we do, it should automatically be closed when it goes out of scope, which is preferable to manually closing. Do you have an example that demonstrates the problem? -Ken
Subject: Re: [rt.cpan.org #83880] [Path::Class:File] slurp() method does not close file handle prior returning
Date: Mon, 11 Mar 2013 15:40:48 +0100
To: bug-Path-Class [...] rt.cpan.org
From: Adam Piątyszek <ediap [...] wp.pl>
* Ken Williams via RT [03/11/2013 03:12 PM]: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=83880 > > > Thanks Adam. > > By opening $fh the way we do, it should automatically be closed when it > goes out of scope, which is preferable to manually closing. Do you have > an example that demonstrates the problem?
Hi Ken, The problem was with my production code running in NFS environment, thus I am not sure if I will be able to crate a minimum testcase showing this on a local disk. The code was doing something like this: my $directory_with_files = Path::Class::Dir( <some directory> ); while ( my $file = $directory_with_files->next ) { # skip anything but *.file next if substr( $file->stringify, -5, 5 ) ne '.file'; my @lines = $file->slurp( chomp => 1 ); # here process the @lines array } # system("ls -la $directory_with_files"); $directory_with_files->rmtree; # system("ls -la $directory_with_files"); The error was coming from the File::Path module. I debugged this by listing the files with the shell 'ls -la' command and one of the files being opened was renamed to ".nfs<some_random_number_here>", which means that the file was still open while the removal operation was in progress. The $file->slurp() operation was the only thing that was opening these files. When I changed the code like this, it started to work without any problems: while ( my $file = $directory_with_files->next ) { # skip anything but *.file next if substr( $file->stringify, -5, 5 ) ne '.file'; my $fh = $file->openr; foreach my $line (<$fh>) { # here process the lines of each file } $fh->close; } $directory_with_files->rmtree; I will try to send you a real case and it's output on an NFS filesystem later today. Thanks, /Adam