Hi all.
I'm working on a patch download tool for Solaris - an interminable task which is almost as much for the experience as for the end product.
I'm using LWP and a non-threaded Perl, between 5.6.0 and 5.8.0, depending on the system the end product's running on. If it matters, I'm testing on Sol8, but the end product will be on servers from 6 to 9.
What I'm currently wrestling with is a bit of a feature creep. I want to have a semidecent indication of progress (how much has been downloaded), and I want to make sure that I have the whole file or no file at all.
What I've done is create a nice little fork to stat the size of the file on a second-by-second basis. Not as nice as a thread, but better than letting it silently proceed with no idea of success or failure.
Here's my question (finally). If someone breaks (SIGINT), I want to unlink the file I'm currently downloading, so I won't have an incomplete file. Unfortunately, using the code below, I'm getting the below message fairly often when I Ctrl-C:
The file is there after execution. The location is correct in the code. What obvious problem am I missing? I'd like to correctly remove the file when the signal handler trips.Couldn't remove incomplete download of 111647-01.zip: No such file or +directory $ ls -la .patchcache/111647-01.zip -rw-r--r-- 1 ferret staff 108175 Aug 20 16:26 111647-01.zip
my $pid; if ( $pid = fork ) { #parent gets child pid local $| = 1; my $res; { sleep 1; print "\rUpdating $file...", sprintf "%-5dk retrieved", ( -s $localfile || 0 ) / +1024 unless $opt{q}; redo unless ( $res = waitpid $pid, WNOHANG ); } print STDERR $res ? " ... done!\n" : " ... failed!\n" unless $opt{q}; return $res?$localfile:0; } else { $SIG{INT} = sub { print STDERR 'Removing incomplete download...'; unlink $localfile or print STDERR "\rCouldn't remove incomplete ". "download of $localfile: $!\n" }; exit is_success( getstore( $uri, $localfile ) ); }
In reply to $SIG{INT} unlink problem by Ferret
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |