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

I am trying to use system call to gnu tar on Windows 2000. I am having some trouble understanding how tar works, exactly. What I want to do is add a file to a tar archive every time it has been changed. I only want the latest copy of the file in the tarball. I assumes that -u switch would do the trick, but it doesn't update the copy of the file already in the tarball, it adds a new copy with the latest changes. What's that all about? How do I accomplish this task. The second part of my question is how do I supress the output of system calls to tar? If I try system ("tar --delete --file=${TimeStamp}.tar \"$FileName\""); and $FileName is not in the tarball, I don't want to hear about it. Can this be done?

Replies are listed 'Best First'.
Re: Using Tar
by Hofmator (Curate) on Mar 07, 2003 at 16:26 UTC
    Why not use the perl module Archive::Tar instead of the system call. You then have no problem with any system output and from the docs it looks like it has a 'remove' method which you could use to implement your update behaviour.

    -- Hofmator

      Why not use the perl module Archive::Tar instead of the system call.

      Archive::Tar requires that the entire tarball is in memory, which for situations of large files is not cool at all and thus its much better, essential really, to shell out to Tar.exe directly.

      For anyone feeling brave a rewrite of Archive::Tar to use temp files would be an interesting and useful project. (Come to think of it, i'm speaking of Version 0.072 here. I havent looked at later versions if there are any.)


      ---
      demerphq


Re: Using Tar
by demerphq (Chancellor) on Mar 07, 2003 at 18:36 UTC

    . I only want the latest copy of the file in the tarball.

    I think you have to delete and then add. But I also dont think that Tar is the right candidate for this job. Im guessing here of course, but perhaps gnu zip is better as it offers this type of operation directly. It doesnt compress as well as tar/zip but its much more suitable for your needs. Also, iirc Tar doesnt like Win32 paths, so you need to chdir into the directory of the file first wheras zip does the right thing.

    The second part of my question is how do I supress the output of system calls to tar?

    system("tar --delete --file foo.tar foo.bar >NULL: 2>&1");
    But dont do that. Maybe
    my $result=`tar --delete --file foo.tar foo.bar 2>&1`;
    is better? Then you can least extract the error if you need to.

    I also think that if your tarballs aren't large then Archive::Tar might be suitable.


    ---
    demerphq