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

I have been working on something that is going to be untarring a file and then taking the contents of the untarred file and copying the files over to another location on the harddisk. However I think I am running into a problem in beteen the untar process and the copy process.

The file untars correctly but when I try to copy it over I get an error saying the file does not exist. Of course I then check the untarred directory and there the files are. I have checked file paths and they are correct, file permissions are correct, and I have even changed directory to the untarred directory and tried that. Still no go.

What I think may be happening is that the File::Copy is trying to copy over the file before it actually shows up from the untar process. Is there anyway I can prove this is what is happening? Also more importantly if this is the case how can I slow the script down and wait for it to show up before trying to copy it without implementing some kind of endless loop checking for it?

Replies are listed 'Best First'.
Re: Archive::Tar then File::Copy?
by talexb (Chancellor) on Mar 15, 2005 at 18:51 UTC

    Is there any reason why you can't un-tar to put the files directly into the location you want? I've used the -C argument for tar at the command line with great success -- does Archive::Tar have the same capability?

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: Archive::Tar then File::Copy?
by talexb (Chancellor) on Mar 15, 2005 at 18:54 UTC

    From the CPAN page:

      $tar->extract_file( $file, [$extract_path] )

      Write an entry, whose name is equivalent to the file name provided to disk. Optionally takes a second parameter, which is the full (unix) path (including filename) the entry will be written to.

    It's amazing what you find when you start looking.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Archive::Tar then File::Copy?
by ambrus (Abbot) on Mar 15, 2005 at 21:43 UTC

    By the time tar has finished the files must be there. Are you running tar (to extract the files) at the same time as the script? If you are, it would be difficult to see when the file actually gets there, the only good way I can think of is to give the output of tar xv to the perl script. So I recommend you to run the tar first and do the copying after the tar process has exitted unless it's absolutely neccessarry to do otherwise.

    If you are doing the copying after untarring, I can't really think of any reason why the extracted files won't show up (unless the untarring and the copying are done on two different machines with some network file system). In that case, I'd check for some tricky errors, like newlines at the end of filenames (I often fall in this trap).

    Update. I didn't really answer your actual question. The short answer is no. It would be possible to wait for a file to appear, but you'd have to wait until the contents of the file are written completely by tar, as surely you don't want to copy a parital file. This is almost impossible to do without doing something with the tar process.

      I am not using the Linux binary tar. I am using the perl module Archive::Tar. Therefore both the untar process and the copy process are both being performed by the script therefore I can not just pipe the output of the tar binary to my perl script.

      I will have to come up with something I guess, it appears no one understands what I am trying to do and I do not know how else to say it.

        To be honest, I'm not entirely convinced that you understand what is going on enough to explain the problem. The reason I say this is that if you're unarchiving via Archive::Tar, by the time that $tar->extract() finishes, all the files are fully present in the output directory. The problem is most likely elsewhere, or the problem is incompletely described.

        A reply falls below the community's threshold of quality. You may see it by logging in.