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:

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
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.
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.