in reply to Tar File To Web Browser

The problem lies in the _get_handle() routine in Archive::Tar.
sub _get_handle { my ($fh, $flags, $mode); sysseek ($_[0], 0, 0); or goto &_drat;
If the filehandle is STDOUT (already opened by web server), that sysseek fails, and _get_handle returns nothing, leading to the errors above. Running this under tests from a normal commandline (thanks Fastolfe), STDOUT is opened freshly and the sysseek succeeds (which is why a lot of tests from the commandline doing the exact same thing worked).

Removing the goto (?!) appears to let sysseek silently fail. If it can get to the beginning, it will, no harm, no foul. If it can't (like in the environment I'm working in), then it just continues on and prints the data successfully. Does that solution seem okay? What are the pitfalls with going with this solution?

Replies are listed 'Best First'.
Re: The Problem & My Solution (please comment)
by Fastolfe (Vicar) on Dec 11, 2000 at 00:52 UTC
    I think a more correct solution (and this isn't something you or I really need to worry about, but the author), might be to do a test against $fh to see if it is pointing to STDOUT, and if so, ignore the seek entirely. I can't think of any cases off the top of my head where a failed seek would be a bad thing in this place, so it might be perfectly OK to simply disregard the return value of this function and let it fail silently if it needs to.
      Are there any cases where a failed seek would be bad?
Re: The Problem & My Solution (please comment)
by a (Friar) on Dec 11, 2000 at 10:07 UTC
    I ran into this a while back, so the details are fuzzy; merlyn had an article in WebTechniques (I hope; found it Programming w/ Perl) which he talked about doing something like this, and the exercise to the reader was to improve it to use compress. I tried and ran up against the above problem. The Author of Archive::Tar was quite helpful, but I don't recall (sorry) the result (use a type glob?) but you could probably contact him for a fix. I believe I did something like the above, hide the seek (ahem) and lived w/ it.

    Update I found the Author's reply (here for the heck of it):
    --- quote
    From: Stephen Zander gibreel@pobox.com>
    To: Andy Bach root@wiwb.uscourts.gov>
    Subject: Re: Archive::Tar

    >> "Andy" == Andy Bach root@wiwb.uscourts.gov> writes:
    We just send back an http header saying tar.gzip file to follow and dump the output to STDOUT and the browser handles the saving, but I couldn't get $tar->write() to use stdout easily, w/ compression on.

    Try using ->write(\*STDOUT) to force the output to the pre-existing STDOUT handle. This should Just Work. If it doesn't I'd appreciate the output of any error logs from apache and information on your environment (eg, apache version perl version, Archive::Tar version, whether you're using mod_perl etc)

    Thanks
    Stephen

    "Farcical aquatic ceremonies are no basis for a system of government!"
    --- end quote

    a