Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Extracting files Using Archive::Tar?

by Flexx (Pilgrim)
on Oct 07, 2002 at 22:35 UTC ( #203517=note: print w/replies, xml ) Need Help??

in reply to Extracting files Using Archive::Tar?

Hi, without much thinking about it, "/.....$submissionID/$user_File_Filename" instantly appears to be quite a strange filename to me. Are you sure you don't mean "../../.$submissionID/$user_File_Filename", or something like that?

Just a "hipshot", but maybe it hits...

Apart from that, It's hard to help you, when you're not providing a minimal test case. Reduce your program to a minimal script that exhibits the error and repost (Chances are you'll discover the bug yourself by doing so). It might well be that the bug is not in the three lines you posted.

For example, it might be that $submissionID or $user_File_Filename might not have the values you'd expect them to hold (print them at some point above the lines you presented to make sure).

You're also not checking the return code of open, Archive::Tar->new and $tar->extract_archive(TARFILE).

Do you use strict and warnings?

So long,

Replies are listed 'Best First'.
Re: Re: Extracting files Using Archive::Tar?
by heezy (Monk) on Oct 08, 2002 at 02:27 UTC

    Ahhh... I see... extract_archive returns something like "Can't find file or directory" sorry I can't remmember exactaly I'm not at work at the mo

    I thank you all for your help with this. If I can't resolve the problem I'll repost to this thread around 10am Mountain Time (-7hGMT)

    Thanks again everyone


Re: Re: Extracting files Using Archive::Tar?
by heezy (Monk) on Oct 08, 2002 at 14:53 UTC

    Hmmm... okay I have no checked all the retrun values as you quite rightly suggested and it appears that $tar->error contains...

    "No such file or directory"

    That is not good.. so I checked and double checked that the file is there, it is. So I thought to make sure I would do an exsits file test (-e) The test found the file.

    So why would Archive::Tar report that the file wasn't there when an exsits test says the file is there?

    Here's the revised code

    sub extractTarFile{ print $cgi->header(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( +time); $year = $year + 1900; $mon = &formatDigit($mon ++); $mday = &formatDigit($mday); $hour = &formatDigit($hour); $min = &formatDigit($min); $sec = &formatDigit($sec); $submissionID = "$year-$mon-$mday-$hour-$min-$sec-$user_Name"; # +yyyy-mm-dd-hhmmss mkdir "$submittedFiles/$submissionID", 0777 or warn "Cannot make d +irectory: $!"; copy ("$tmpFilePosition", "$submittedFiles/$submissionID/$user_Fil +e_Filename"); $tarLocation = "$submittedFiles/$submissionID/$user_File_Filename" +; $RC_open = open TARFILE, $tarLocation; if (-e TARFILE){ print $cgi->p("File exsists"); } $RC_new = $tar = Archive::Tar->new(); $RC_extract = $tar->extract_archive("TARFILE"); $tar_errors = $tar->error(); print $cgi->p("Return Val open ($RC_open)"); print $cgi->p("Return Val New tar ($RC_new)"); print $cgi->p("Return Val Extract ($RC_extract)"); print $cgi->p("Tar Location is ($tarLocation)"); print $cgi->p("Tar errors ($tar_errors)"); print $cgi->p("submittedFiles ($submittedFiles)"); print $cgi->p("submissionID ($submissionID)"); print $cgi->p("userFileFilename ($user_File_Filename)"); close TARFILE; }

    And the new output from the browser...

    File exsists
    Return Val open (1)
    Return Val New tar (Archive::Tar=HASH(0x3be9cc))
    Return Val Extract ()
    Tar Location is (/webroot/service/servicelist_submission/submitted_files/2002-09-08-08-32-25-Mark/sample.tar)
    Tar errors (No such file or directory)
    submittedFiles (/webroot/service/servicelist_submission/submitted_files)
    submissionID (2002-09-08-08-32-25-Mark)
    userFileFilename (sample.tar)

    Whilst I'm at it I'll show you the permissions on the files as well although I don't think it's that...?...

    mf139823@esweb: pwd
    308 mf139823@esweb: ls -l
    total 932
    drwxr-xr-x   2 nobody   nobody       512 Oct  8 08:32 ./
    drwxrwxrwx  23 mf139823 staff       1024 Oct  8 08:32 ../
    -rw-r--r--   1 nobody   nobody    461824 Oct  8 08:32 sample.tar

    Am I doing something crazy?

    Please help!


      I realise

      $RC_extract = $tar->extract_archive("TARFILE");

      Should actually be written without the quotation marks around TARFILE. I have now changed this but $tar->error still maintains it can't find the file??....ideas?..Anyone?


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://203517]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2022-10-05 08:57 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (21 votes). Check out past polls.