Commit | Line | Data |
---|---|---|
39713df4 RGS |
1 | package Archive::Tar::Constant; |
2 | ||
3 | BEGIN { | |
4 | require Exporter; | |
93e94d8a | 5 | |
19606b44 | 6 | $VERSION = '2.04'; |
642eb381 | 7 | @ISA = qw[Exporter]; |
39713df4 RGS |
8 | |
9 | require Time::Local if $^O eq "MacOS"; | |
10 | } | |
11 | ||
501bd44a | 12 | @EXPORT = Archive::Tar::Constant->_list_consts( __PACKAGE__ ); |
642eb381 | 13 | |
39713df4 RGS |
14 | use constant FILE => 0; |
15 | use constant HARDLINK => 1; | |
16 | use constant SYMLINK => 2; | |
17 | use constant CHARDEV => 3; | |
18 | use constant BLOCKDEV => 4; | |
19 | use constant DIR => 5; | |
20 | use constant FIFO => 6; | |
21 | use constant SOCKET => 8; | |
22 | use constant UNKNOWN => 9; | |
23 | use constant LONGLINK => 'L'; | |
24 | use constant LABEL => 'V'; | |
25 | ||
26 | use constant BUFFER => 4096; | |
27 | use constant HEAD => 512; | |
28 | use constant BLOCK => 512; | |
29 | ||
642eb381 SH |
30 | use constant COMPRESS_GZIP => 9; |
31 | use constant COMPRESS_BZIP => 'bzip2'; | |
32 | ||
39713df4 RGS |
33 | use constant BLOCK_SIZE => sub { my $n = int($_[0]/BLOCK); $n++ if $_[0] % BLOCK; $n * BLOCK }; |
34 | use constant TAR_PAD => sub { my $x = shift || return; return "\0" x (BLOCK - ($x % BLOCK) ) }; | |
35 | use constant TAR_END => "\0" x BLOCK; | |
36 | ||
37 | use constant READ_ONLY => sub { shift() ? 'rb' : 'r' }; | |
38 | use constant WRITE_ONLY => sub { $_[0] ? 'wb' . shift : 'w' }; | |
39 | use constant MODE_READ => sub { $_[0] =~ /^r/ ? 1 : 0 }; | |
40 | ||
3c4b39be | 41 | # Pointless assignment to make -w shut up |
39713df4 RGS |
42 | my $getpwuid; $getpwuid = 'unknown' unless eval { my $f = getpwuid (0); }; |
43 | my $getgrgid; $getgrgid = 'unknown' unless eval { my $f = getgrgid (0); }; | |
97a504ba RGS |
44 | use constant UNAME => sub { $getpwuid || scalar getpwuid( shift() ) || '' }; |
45 | use constant GNAME => sub { $getgrgid || scalar getgrgid( shift() ) || '' }; | |
39713df4 RGS |
46 | use constant UID => $>; |
47 | use constant GID => (split ' ', $) )[0]; | |
48 | ||
49 | use constant MODE => do { 0666 & (0777 & ~umask) }; | |
50 | use constant STRIP_MODE => sub { shift() & 0777 }; | |
51 | use constant CHECK_SUM => " "; | |
52 | ||
f8c9502f | 53 | use constant UNPACK => 'A100 A8 A8 A8 a12 A12 A8 A1 A100 A6 A2 A32 A32 A8 A8 A155 x12'; # cdrake - size must be a12 - not A12 - or else screws up huge file sizes (>8gb) |
39713df4 RGS |
54 | use constant PACK => 'a100 a8 a8 a8 a12 a12 A8 a1 a100 a6 a2 a32 a32 a8 a8 a155 x12'; |
55 | use constant NAME_LENGTH => 100; | |
56 | use constant PREFIX_LENGTH => 155; | |
57 | ||
93e94d8a | 58 | use constant TIME_OFFSET => ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,70) : 0; |
39713df4 RGS |
59 | use constant MAGIC => "ustar"; |
60 | use constant TAR_VERSION => "00"; | |
61 | use constant LONGLINK_NAME => '././@LongLink'; | |
642eb381 | 62 | use constant PAX_HEADER => 'pax_global_header'; |
39713df4 | 63 | |
642eb381 | 64 | ### allow ZLIB to be turned off using ENV: DEBUG only |
81a5970e RGS |
65 | use constant ZLIB => do { !$ENV{'PERL5_AT_NO_ZLIB'} and |
66 | eval { require IO::Zlib }; | |
93e94d8a | 67 | $ENV{'PERL5_AT_NO_ZLIB'} || $@ ? 0 : 1 |
642eb381 SH |
68 | }; |
69 | ||
93e94d8a | 70 | ### allow BZIP to be turned off using ENV: DEBUG only |
642eb381 SH |
71 | use constant BZIP => do { !$ENV{'PERL5_AT_NO_BZIP'} and |
72 | eval { require IO::Uncompress::Bunzip2; | |
73 | require IO::Compress::Bzip2; }; | |
93e94d8a | 74 | $ENV{'PERL5_AT_NO_BZIP'} || $@ ? 0 : 1 |
642eb381 SH |
75 | }; |
76 | ||
39713df4 | 77 | use constant GZIP_MAGIC_NUM => qr/^(?:\037\213|\037\235)/; |
642eb381 | 78 | use constant BZIP_MAGIC_NUM => qr/^BZh\d/; |
39713df4 | 79 | |
2610e7a4 | 80 | use constant CAN_CHOWN => sub { ($> == 0 and $^O ne "MacOS" and $^O ne "MSWin32") }; |
39713df4 RGS |
81 | use constant CAN_READLINK => ($^O ne 'MSWin32' and $^O !~ /RISC(?:[ _])?OS/i and $^O ne 'VMS'); |
82 | use constant ON_UNIX => ($^O ne 'MSWin32' and $^O ne 'MacOS' and $^O ne 'VMS'); | |
93e94d8a | 83 | use constant ON_VMS => $^O eq 'VMS'; |
39713df4 | 84 | |
501bd44a CBW |
85 | sub _list_consts { |
86 | my $class = shift; | |
87 | my $pkg = shift; | |
88 | return unless defined $pkg; # some joker might use '0' as a pkg... | |
89 | ||
90 | my @rv; | |
91 | { no strict 'refs'; | |
92 | my $stash = $pkg . '::'; | |
93 | ||
94 | for my $name (sort keys %$stash ) { | |
95 | ||
96 | ### is it a subentry? | |
97 | my $sub = $pkg->can( $name ); | |
98 | next unless defined $sub; | |
99 | ||
100 | next unless defined prototype($sub) and | |
101 | not length prototype($sub); | |
102 | ||
103 | push @rv, $name; | |
104 | } | |
105 | } | |
106 | ||
107 | return sort @rv; | |
108 | } | |
109 | ||
39713df4 | 110 | 1; |