R
Rex Gustavus Adolphus
Hej hej
This
I recently got problems with this (rather ugly, it was one of my
first) subroutine:
sub check_for_file {
my ($dbh, $filename,$wait_after_last_write, $msglevel) = @_;
my ($file);
my @files;
my $age_in_seconds;
&printlog($msglevel,3,"looking for $filename");
@files = glob($filename);
FILENAME: foreach $file (@files) {
next FILENAME unless -s $file; # next iteration of the
loop unless file exists
$age_in_seconds = time() - (stat($file))[9];
&printlog($msglevel,3,"Found $file, last changed
$age_in_seconds seconds ago."
. " Should be older than
$wait_after_last_write seconds");
return($file) if ($age_in_seconds >=
$wait_after_last_write);
}
return;
}
On a couple of rare, unrepeatable instances, this has caused the
following:
Read on closed filehandle <_GEN_0> at xxxx line 39, <_GEN_0> chunk
yyyyy.
where line 39 is the line with the call to glob.
I'm not at that site now, but it's an older perl, 5.005, I think,
running on Solaris, (sorry for being so vague).
I've done a bit of research and found this thread from last century:
http://groups.google.com/groups?hl=...&q=read+on+closed+filehandle+glob&sa=N&tab=wg
This seems to be just like my case.
I didn't think my code opened any file descriptors at all.
In other parts of the program I am renaming or moving the found file
with this code:
sub move_file {
my ($dbh, $to_dir, $file, $msglevel) = @_;
my $target = $to_dir;
if ( -d $to_dir ) {
$target .= "/".basename($file);
}
&printlog($msglevel,3,"moving $file to $target");
if ( (rename $file => $target ) or move($file,$target) ) {
return $target;
} else {
printlog($msglevel,0,"rename $file to $target failed, system
message:$!");
rename $file => $file.time()
or die "$0 terminates due to problems moving
files:\n$0 $!\n";
return;
}
} # end of sub move_file
So finally my questions:
Does glob open file descriptors for the found files?
Does rename or File::move open file descriptors?
Would using File::glob solve the issue?
Thanx for reading so far.
This
I recently got problems with this (rather ugly, it was one of my
first) subroutine:
sub check_for_file {
my ($dbh, $filename,$wait_after_last_write, $msglevel) = @_;
my ($file);
my @files;
my $age_in_seconds;
&printlog($msglevel,3,"looking for $filename");
@files = glob($filename);
FILENAME: foreach $file (@files) {
next FILENAME unless -s $file; # next iteration of the
loop unless file exists
$age_in_seconds = time() - (stat($file))[9];
&printlog($msglevel,3,"Found $file, last changed
$age_in_seconds seconds ago."
. " Should be older than
$wait_after_last_write seconds");
return($file) if ($age_in_seconds >=
$wait_after_last_write);
}
return;
}
On a couple of rare, unrepeatable instances, this has caused the
following:
Read on closed filehandle <_GEN_0> at xxxx line 39, <_GEN_0> chunk
yyyyy.
where line 39 is the line with the call to glob.
I'm not at that site now, but it's an older perl, 5.005, I think,
running on Solaris, (sorry for being so vague).
I've done a bit of research and found this thread from last century:
http://groups.google.com/groups?hl=...&q=read+on+closed+filehandle+glob&sa=N&tab=wg
This seems to be just like my case.
I didn't think my code opened any file descriptors at all.
In other parts of the program I am renaming or moving the found file
with this code:
sub move_file {
my ($dbh, $to_dir, $file, $msglevel) = @_;
my $target = $to_dir;
if ( -d $to_dir ) {
$target .= "/".basename($file);
}
&printlog($msglevel,3,"moving $file to $target");
if ( (rename $file => $target ) or move($file,$target) ) {
return $target;
} else {
printlog($msglevel,0,"rename $file to $target failed, system
message:$!");
rename $file => $file.time()
or die "$0 terminates due to problems moving
files:\n$0 $!\n";
return;
}
} # end of sub move_file
So finally my questions:
Does glob open file descriptors for the found files?
Does rename or File::move open file descriptors?
Would using File::glob solve the issue?
Thanx for reading so far.