http://qs321.pair.com?node_id=351105

stefan k has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks, I've created a CGI script which returns a TAR-archive, built using Archive::Tar. Can anyone point me in the right direction where to search for clues?

Regards... Stefan
you begin bashing the string with a +42 regexp of confusion

Replies are listed 'Best First'.
Re: CGI-Attachment with many \0's
by UnderMine (Friar) on May 06, 2004 at 13:44 UTC
    Can I have a bit more information and clarification.

    Have you tried getting the script to write the file to disk and if you have, can this file be retrieved by the clients correctly?

    If you have and both were successful have you tried having the script simultaniously write a copy of the file and return it to the client? Comparing the results might give us some more pointers to work with.

    Thanks
    UnderMine

      Hi,

      Have you tried getting the script to write the file to disk

      Yes

      can this file be retrieved by the clients correctly?

      Yes, I've written that file to the /tmp-Dir, copied it to the HTTPD-root-directory accessed it directly and could download it just fine.

      have you tried having the script simultaniously write a copy of the file and return it to the client?

      No, I am using the following code:

      my $tar = Archive::Tar->new; # ... # in a loop: $tar->add_files("$filename"); # ... my $data = $tar->write(); print $q->header(-type => 'application/octet-stream', -attachment => "edi.tar"); print $data;
      And remember: it works fine on two out of three machines. That is what makes me wonder so much.

      Regards... Stefan
      you begin bashing the string with a +42 regexp of confusion

        How different are the httpd.conf files for the two redhat machines? Are there any extra later steps the data stream goes though? Eg one running Apache::Compress on the output stream.

        Hope it helps
        UnderMine

Re: CGI-Attachment with many \0's
by matija (Priest) on May 06, 2004 at 13:54 UTC
    Are you using binmode when writing the files?

    Are the local settings the same on both machines? (As soon as you mention RedHat, I think of locale problems).

      Hi,

      Are you using binmode when writing the files?

      No, I thought that were only important when dealing with different platforms. And it ran fine on the Windowsmachine and with Windowsclients.

      Are the local settings the same on both machines? (As soon as you mention RedHat, I think of locale problems).

      And how much I fought with them! They made me XEmacs broken, but that's another story. The locale setting differs: the good box has

      LANG="en_US.iso88591" SYSFONT="latarcyrheb-sun16"
      the bad box has
      LANG="en_US" SUPPORTED="en_US" SYSFONT="latarcyrheb-sun16"
      Can _that_ be a problem??

      Regards... Stefan
      you begin bashing the string with a +42 regexp of confusion

Re: CGI-Attachment with many \0's
by eXile (Priest) on May 06, 2004 at 17:25 UTC
    Hi,

    Are the files you add to the archive readable for the user-id the script runs under? Normally CGI scripts run under user 'nobody', so the files should at least be readable for this user.

      hi,
      yes, they are. Actually, the script first generates the files (using File::Temp::tempfile as a name generator) and then tries to pack them all together.

      Regards... Stefan
      you begin bashing the string with a +42 regexp of confusion

        mmm, at what point do you actually check if these files are there?

        What I'd do, because it is a strange problem, is use perl -d to step through your code on the box where the problem appears, maybe set a breakpoint just before the archive is created and at that point check if the files are there and what their size is (or add print/system commands in your source code to debug, depending on your debugging style).

        Another thing that might be going wrong when your script generates the files is that the file-content still is in the output buffer instead of on disk. You can set $|=1 to avoid this.