tags:

views:

397

answers:

3

I'm using Perl's Archive::Tar module. It preserves the file permissions but doesn't preserve the sticky bit. At the other end where I extract the archive, all the sticky bits are gone. I think UNIX/LINUX operating system stores these sticky bits somewhere else. How can I make my archive preserve sticky bits also?

Using the -p switch to tar preserves it but how do I do it using Archive::Tar? I'm using Perl's module on both the sides.

A: 

Not sure, but on the official tar command, you need to pass -p to make this happen

Paul Betts
A: 

You might want to take a look at the Archive::Tar documentation for the details. From a brief glance, it appears that

$Archive::Tar::CHMOD = 1;

should do what you want, although the documentation claims that the above setting is the default. It may be that Archive::Tar strips off the higher-order mode bits like the sticky bit.

Is the archive both created and extracted with Archive::Tar, or are you using the standard tar program at one end or the other?

Dale Hagglund
+4  A: 

According to the Fine Source, Archive::Tar::File strips off the high bits from the mode. You can try the following magic incantation at the beginning of your script (before anything might have referenced Archive::Tar) and see if that subverts it:

use Archive::Tar::Constant ();
BEGIN {
    local $SIG{__WARN__} = sub{};
    *Archive::Tar::Constant::STRIP_MODE = sub(){ sub {shift} };
}
...
use Archive::Tar;
...

Brief explanation: STRIP_MODE is a constant that contains a subroutine that can be passed the raw mode and returns the mode that should be stored. It is normally set to

sub { shift() & 0777 }

Because it is a constant, imported from Archive::Tar::Constant into Archive::Tar::File and used there, whatever it is set to will be inlined into Archive::Tar::File as it is compiled. So to change it, the constant must be changed before it is inlined, that is, before Archive::Tar::File ever gets loaded.

N.B. Because changing an inlinable constant is prone to error (changing it after it is too late to have any effect), it normally generates a severe warning that can't be disabled by usual means.

ysth