Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

CGI-Attachment with many \0's

by stefan k (Curate)
on May 06, 2004 at 13:34 UTC ( #351105=perlquestion: print w/ replies, xml ) Need Help??
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.
  • The script runs fine on a Linux-box (Red Hat 9).
  • It also runs on some windows box.
  • On both machines you can connect with different clients (tested w3m, mozilla, konqueror).
  • But on a second Linux-box (also Red Hat 9) it delivers TAR-archives which contain the filenames all-right but otherwise only \0s (x00). ????
  • On that box it can create the tarballs as a file but can't deliver them correctly.
  • Both linux boxen have (almost) the same httpd.conf, only differences in UserDir-related settings. I can't tell whether there might be any important differences but obviously there are.
  • I've tried MIME-types: "application/x-tar", and "../octet-stream".
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

Comment on CGI-Attachment with many \0's
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://351105]
Approved by jeffa
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-10-25 01:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (139 votes), past polls