in reply to Extracting files Using Archive::Tar?
I rewrote your subroutine, and changed something:
sub extractTarFile { my ($strftime, $submissionID, $cur_submit_dir, $tarLocation, $old_cwd, $tar, $RC_extract); my ($user_Name, $tmpFilePosition, $user_File_Filename) = @_; # just to save some typing $strftime = POSIX::strftime("%Y-%m-%d-%H-%M-%S", localtime); # note that this ID is not unique $submissionID = "$strftime-$user_Name"; $cur_submit_dir = "$submittedFiles/$submissionID"; $tarLocation = "$cur_submit_dir/$user_File_Filename"; # do you really need to create a world writable directory? mkdir($cur_submit_dir, 0755) or die "Cannot make directory: $! +"; copy("$tmpFilePosition", "$tarLocation") or die "copy failed: +$!"; # store our current working directory $old_cwd = Cwd::cwd; # change to submitted files current dir Cwd::chdir($cur_submit_dir); $tar = Archive::Tar->new(); $RC_extract = $tar->extract_archive($tarLocation); # restore previous working dir Cwd::chdir $old_cwd; return $RC_extract, $tar->error(); }
Few notes: Archive::Tar extracts archives in current directory, so you need to change your working directory before extracting and possibly restore it when done. I also used strftime, checked return values of file operations instead using -e and removed the open that was unnecessary. All paths must be absolute.
Ciao, Valerio
Update:You are welcome heezy :) I couldn't
believe my eyes when I realized that I was writing somewhere
else...
Oh, I forgot to do some final cleaning: we should remove
submitted files from $tmpFilePosition and $tarLocation...
Ciao!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Extracting files Using Archive::Tar?
by heezy (Monk) on Oct 08, 2002 at 18:41 UTC |