releasing/cbrtools/perl/Archive/Tar.pm
author jjkang
Fri, 25 Jun 2010 19:56:45 +0800
changeset 604 b33dd54aaa52
parent 602 3145852acc89
permissions -rw-r--r--
add cpptoolsplat
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Copyright 1997 Calle Dybedahl. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# Copyright 1998 Stephen Zander. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# It is currently developed by Stephen Zander <gibreel@pobox.com>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# This library is free software; you can redistribute it and/or modify
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# it under the same terms as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
package Archive::Tar;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
use Carp qw(carp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
use Cwd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
use Fcntl qw(O_RDONLY O_RDWR O_WRONLY O_CREAT O_TRUNC F_DUPFD F_GETFL);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
use File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
use Symbol;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
require Time::Local if $^O eq "MacOS";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
$VERSION = do { my @a=q$Name: version_0_22 $ =~ /\d+/g; sprintf "%d." . ("%02d" x $#a ),@a };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
require Exporter;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
@ISA = qw(Exporter);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
@EXPORT_OK = qw(FILE HARDLINK SYMLINK 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
		CHARDEV BLOCKDEV DIR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
		FIFO SOCKET INVALID);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
%EXPORT_TAGS = (filetypes => \@EXPORT_OK);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
# Check if symbolic links are available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
my $symlinks = eval { readlink $0 or 1; };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
carp "Symbolic links not available"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
    unless $symlinks || !$^W;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
# Check if Compress::Zlib is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
my $compression = eval { 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
    local $SIG{__DIE__};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
    require Compress::Zlib; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
    sub Compress::Zlib::gzFile::gzseek {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
	my $tmp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
	$_[0]->gzread ($tmp, 4096), $_[1] -= 4096
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
	    while ($_[1] > 4096);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
	$_[0]->gzread ($tmp, $_[1])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
	  if $_[1];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
    1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
carp "Compression not available"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
    unless $compression || !$^W;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
# Check for get* (they don't exist on WinNT)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
my $fake_getpwuid;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
$fake_getpwuid = "unknown"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
    unless eval { $_ = getpwuid (0); }; # Pointless assigment to make -w shut up
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
my $fake_getgrgid;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
$fake_getgrgid = "unknown"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
    unless eval { $_ = getgrgid (0); }; # Pointless assigment to make -w shut up
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
# Automagically detect gziped files if they start with this
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
my $gzip_magic_number = "^(?:\037\213|\037\235)";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
my $tar_unpack_header 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
    = 'A100 A8 A8 A8 A12 A12 A8 A1 A100 A6 A2 A32 A32 A8 A8 A155 x12';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
my $tar_pack_header
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
    = 'a100 a8 a8 a8 a12 a12 A8 a1 a100 a6 a2 a32 a32 a8 a8 a155 x12',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
my $tar_header_length = 512;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
my $time_offset = ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,70) : 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
## Subroutines to return type constants 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
sub FILE() { return 0; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
sub HARDLINK() { return 1; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
sub SYMLINK() { return 2; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
sub CHARDEV() { return 3; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
sub BLOCKDEV() { return 4; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
sub DIR() { return 5; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
sub FIFO() { return 6; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
sub SOCKET() { return 8; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
sub UNKNOWN() { return 9; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
###
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
### Non-method functions
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
###
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
my $error;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
sub _drat {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
    $error = $! . '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
    return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
sub error {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
    $error;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
sub set_error {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
    shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
    $error = "@_";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
## filetype -- Determine the type value for a given file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
sub filetype {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
    my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
    return SYMLINK
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
	if (-l $file);		# Symlink
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
    return FILE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
	if (-f _);		# Plain file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
    return DIR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
	if (-d _);		# Directory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
    return FIFO
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
	if (-p _);		# Named pipe
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
    return SOCKET
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
	if (-S _);		# Socket
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
    return BLOCKDEV
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
	if (-b _);		# Block special
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
    return CHARDEV
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
	if (-c _);		# Character special
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
    return UNKNOWN;		# Something else (like what?)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
sub _make_special_file_UNIX {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
    # $file is the last component of $entry->{name}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
    my ($entry, $file) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
    if ($entry->{type} == SYMLINK) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
	symlink $entry->{linkname}, $file or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
	    $^W && carp ("Making symbolic link from ", $entry->{linkname}, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
			 " to ", $entry->{name}, ", failed.\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
    elsif ($entry->{type} == HARDLINK) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
	link $entry->{linkname}, $file or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
	    $^W && carp ("Hard linking ", $entry->{linkname}, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
			 " to ", $entry->{name}, ", failed.\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
    elsif ($entry->{type} == FIFO) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
	system("mknod","$file","p") or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
	    $^W && carp "Making fifo ", $entry->{name}, ", failed.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
    elsif ($entry->{type} == BLOCKDEV) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
	system("mknod","$file","b",$entry->{devmajor},$entry->{devminor}) or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
	    $^W && carp ("Making block device ", $entry->{name},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
			 " (maj=", $entry->{devmajor}, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
			 ", min=", $entry->{devminor}, "), failed.\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
    elsif ($entry->{type} == CHARDEV) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
	system("mknod", "$file", "c", $entry->{devmajor}, $entry->{devminor}) or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
	    $^W && carp ("Making block device ", $entry->{name}, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
			 " (maj=", $entry->{devmajor}, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
			 " ,min=", $entry->{devminor}, "), failed.\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
sub _make_special_file_Win32 {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
    # $file is the last component of $entry->{name}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
    my ($entry, $file) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
    if ($entry->{type} == SYMLINK) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
	$^W && carp ("Making symbolic link from ", $entry->{linkname}, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
		     " to ", $entry->{name}, ", failed.\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
    elsif ($entry->{type} == HARDLINK) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
	link $entry->{linkname}, $file or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
	    $^W && carp ("Making hard link from ", $entry->{linkname}, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
			 " to ", $entry->{name}, ", failed.\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
    elsif ($entry->{type} == FIFO) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
	$^W && carp "Making fifo ", $entry->{name}, ", failed.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
    elsif ($entry->{type} == BLOCKDEV) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
	$^W && carp ("Making block device ", $entry->{name},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
		     " (maj=", $entry->{devmajor}, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
		     ", min=", $entry->{devminor}, "), failed.\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
    elsif ($entry->{type} == CHARDEV) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
	$^W && carp ("Making block device ", $entry->{name},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
		     " (maj=", $entry->{devmajor}, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
		     " ,min=", $entry->{devminor}, "), failed.\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
*_make_special_file = $^O eq "MSWin32" ? 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
    \&_make_special_file_Win32 : \&_make_special_file_UNIX;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
sub _munge_file {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
#  Mac path to the Unix like equivalent to be used in tar archives
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
    my $inpath = $_[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
#  If there are no :'s in the name at all, assume it's a single item in the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
#  current directory.  Return it, changing any / in the name into :
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
    if ($inpath !~ m,:,) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
	$inpath =~ s,/,:,g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
	return $inpath;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
#  If we now split on :, there will be just as many nulls in the list as
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
#  there should be up requests, except if it begins with a :, where there
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
#  will be one extra.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
    my @names = split (/:/, $inpath);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
    shift (@names)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
	if ($names[0] eq "");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
    my @outname = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
#  Work from the end.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
    my $i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
    for ($i = $#names; $i >= 0; --$i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
	if ($names[$i] eq "") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
	    unshift (@outname, "..");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
	} 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
	else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
	    $names[$i] =~ s,/,:,g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
	    unshift (@outname, $names[$i]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
    my $netpath = join ("/", @outname);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
    $netpath = $netpath . "/" if ($inpath =~ /:$/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
    if ($inpath !~ m,^:,) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
	return "/".$netpath;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
    } 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
	return $netpath;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
sub _get_handle {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
    my ($fh, $flags, $mode);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
    sysseek ($_[0], 0, 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
	or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
    if ($^O eq "MSWin32") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
	$fh = $_[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
	$fh = fcntl ($_[0], F_DUPFD, 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
    if ($compression && (@_ < 2 || $_[1] != 0)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
	$mode = $#_ ? (int($_[1]) > 1 ?
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
			  "wb".int($_[1]) : "wb") : "rb";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
	$fh = Compress::Zlib::gzdopen_ ($fh, $mode, 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
	    or &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
	$flags = fcntl ($_[0], F_GETFL, 0) & (O_RDONLY | O_WRONLY | O_RDWR);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
	$mode = ($flags == O_WRONLY) ? ">&=$fh" : 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
	    ($flags == O_RDONLY) ? "<&=$fh" : "+>&=$fh";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
	$fh = gensym;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
	open ($fh, $mode)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
	  or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
	$fh = bless *{$fh}{IO}, "Archive::Tar::_io";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
	binmode $fh
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
    return $fh;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
sub _read_tar {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
    my ($file, $seekable, $extract) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
    my $tarfile = [];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
    my ($head, $offset, $size);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
    $file->gzread ($head, $tar_header_length)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
	or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
    if (substr ($head, 0, 2) =~ /$gzip_magic_number/o) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
	$error =
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
	    "Compression not available\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
	return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
    $offset = $tar_header_length
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
	if $seekable;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
 READLOOP:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
    while (length ($head) == $tar_header_length) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
	my ($name,		# string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
	    $mode,		# octal number
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
	    $uid,		# octal number
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
	    $gid,		# octal number
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
	    $size,		# octal number
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
	    $mtime,		# octal number
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
	    $chksum,		# octal number
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
	    $type,		# character
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
	    $linkname,		# string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
	    $magic,		# string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
	    $version,		# two bytes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
	    $uname,		# string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
	    $gname,		# string
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
	    $devmajor,		# octal number
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
	    $devminor,		# octal number
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
	    $prefix) = unpack ($tar_unpack_header, $head);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
	my ($data, $block, $entry);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
	$mode = oct $mode;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
	$uid = oct $uid;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
	$gid = oct $gid;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
	$size = oct $size;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
	$mtime = oct $mtime;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
	$chksum = oct $chksum;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
	$devmajor = oct $devmajor;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
	$devminor = oct $devminor;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
	$name = $prefix."/".$name if $prefix;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
	$prefix = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
	# some broken tar-s don't set the type for directories
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
	# so we ass_u_me a directory if the name ends in slash
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
	$type = DIR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
	    if $name =~ m|/$| and $type == FILE;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
	last READLOOP if $head eq "\0" x 512; # End of archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
	# Apparently this should really be two blocks of 512 zeroes,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
	# but GNU tar sometimes gets it wrong. See comment in the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
	# source code (tar.c) to GNU cpio.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
	substr ($head, 148, 8) = "        ";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
	if (unpack ("%16C*", $head) != $chksum) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
	   warn "$name: checksum error.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
	unless ($extract || $type != FILE) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
	    # Always read in full 512 byte blocks
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
	    $block = $size & 0x01ff ? ($size & ~0x01ff) + 512 : $size;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
	    if ($seekable) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
		while ($block > 4096) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
		    $file->gzread ($data, 4096)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
			or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
		    $block -= 4096;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
		$file->gzread ($data, $block)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
		    or goto &_drat
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
			if ($block);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
		# Ignore everything we've just read.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
		undef $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
	    } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
		if ($file->gzread ($data, $block) < $block) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
		    $error = "Read error on tarfile.";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
		    return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
		# Throw away any trailing garbage
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
		substr ($data, $size) = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
	    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   363
	# Guard against tarfiles with garbage at the end
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   364
	last READLOOP if $name eq ''; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   365
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
	$entry = {name => $name,		    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
		  mode => $mode,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
		  uid => $uid,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
		  gid => $gid,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
		  size => $size,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
		  mtime => $mtime,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
		  chksum => $chksum,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
		  type => $type,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
		  linkname => $linkname,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
		  magic => $magic,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
		  version => $version,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
		  uname => $uname,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
		  gname => $gname,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
		  devmajor => $devmajor,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
		  devminor => $devminor,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
		  prefix => $prefix,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
		  offset => $offset,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
		  data => $data};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
	if ($extract) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
	    _extract_file ($entry, $file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
	    $file->gzread ($head, 512 - ($size & 0x1ff)) 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
		or goto &_drat
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
		    if ($size & 0x1ff && $type == FILE);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
	else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
	    push @$tarfile, $entry;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
	if ($seekable) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
	    $offset += $tar_header_length;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
	    $offset += ($size & 0x01ff) ? ($size & ~0x01ff) + 512 : $size
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
		if $type == FILE;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
	$file->gzread ($head, $tar_header_length) 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
    $file->gzclose ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
	unless $seekable;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
    return $tarfile
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
	unless $extract;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
sub _format_tar_entry {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
    my ($ref) = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
    my ($tmp,$file,$prefix,$pos);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   415
    $file = $ref->{name};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   416
    if (length ($file) > 99) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   417
	$pos = index $file, "/", (length ($file) - 100);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   418
	next
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   419
	    if $pos == -1;	# Filename longer than 100 chars!
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   420
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   421
	$prefix = substr $file,0,$pos;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   422
	$file = substr $file,$pos+1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   423
	substr ($prefix, 0, -155) = ""
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   424
	    if length($prefix)>154;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   425
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   426
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   427
	$prefix="";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   428
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   429
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   430
    $tmp = pack ($tar_pack_header,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   431
		 $file,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   432
		 sprintf("%06o ",$ref->{mode}),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   433
		 sprintf("%06o ",$ref->{uid}),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   434
		 sprintf("%06o ",$ref->{gid}),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   435
		 sprintf("%11o ",$ref->{size}),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   436
		 sprintf("%11o ",$ref->{mtime}),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   437
		 "",		#checksum field - space padded by pack("A8")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   438
		 $ref->{type},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   439
		 $ref->{linkname},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   440
		 $ref->{magic},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   441
		 $ref->{version} || '00',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   442
		 $ref->{uname},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   443
		 $ref->{gname},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   444
		 sprintf("%6o ",$ref->{devmajor}),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   445
		 sprintf("%6o ",$ref->{devminor}),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   446
		 $prefix);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   447
    substr($tmp,148,7) = sprintf("%6o\0", unpack("%16C*",$tmp));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   448
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   449
    return $tmp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   450
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   451
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   452
sub _format_tar_file {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   453
    my @tarfile = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   454
    my $file = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   455
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   456
    foreach (@tarfile) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   457
	$file .= _format_tar_entry $_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   458
	$file .= $_->{data};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   459
	$file .= "\0" x (512 - ($_->{size} & 0x1ff))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   460
	    if ($_->{size} & 0x1ff);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   461
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   462
    $file .= "\0" x 1024;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   463
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   464
    return $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   465
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   466
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   467
sub _write_tar {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   468
    my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   469
    my $entry;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   470
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   471
    foreach $entry ((ref ($_[0]) eq 'ARRAY') ? @{$_[0]} : @_) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   472
	next
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   473
	    unless (ref ($entry) eq 'HASH');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   474
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   475
	my $src;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   476
        if ($^O eq "MacOS") {  #convert back from Unix to Mac path
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   477
            my @parts = split(/\//, $entry->{name});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   478
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   479
            $src = $parts[0] ? ":" : "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   480
            foreach (@parts) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   481
		next if !$_ || $_ eq ".";  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   482
                s,:,/,g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   483
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   484
		$_ = ":"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   485
		    if ($_ eq "..");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   486
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   487
		$src .= ($src =~ /:$/) ? $_ : ":$_";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   488
	    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   489
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   490
	else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   491
            $src = $entry->{name};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   492
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   493
	sysopen (FH, $src, O_RDONLY)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   494
	    && binmode (FH)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   495
		or next
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   496
		    unless $entry->{type} != FILE || $entry->{data};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   497
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   498
	$file->gzwrite (_format_tar_entry ($entry))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   499
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   500
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   501
	if ($entry->{type} == FILE) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   502
	    if ($entry->{data}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   503
		$file->gzwrite ($entry->{data})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   504
		    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   505
	    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   506
	    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   507
		my $size = $entry->{size};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   508
		my $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   509
		while ($size >= 4096) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   510
		    sysread (FH, $data, 4096)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   511
			&& $file->gzwrite ($data)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   512
			    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   513
		    $size -= 4096;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   514
		}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   515
		sysread (FH, $data, $size)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   516
		    && $file->gzwrite ($data)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   517
			or goto &_drat
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   518
			    if $size;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   519
		close FH;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   520
	    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   521
	    $file->gzwrite ("\0" x (512 - ($entry->{size} & 511)))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   522
		or goto &_drat
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   523
		    if ($entry->{size} & 511);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   524
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   525
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   526
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   527
    $file->gzwrite ("\0" x 1024)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   528
	and !$file->gzclose ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   529
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   530
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   531
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   532
sub _add_file {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   533
    my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   534
    my ($mode,$nlnk,$uid,$gid,$rdev,$size,$mtime,$type,$linkname);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   535
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   536
    if (($mode,$nlnk,$uid,$gid,$rdev,$size,$mtime) = (lstat $file)[2..7,9]) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   537
	$linkname = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   538
	$type = filetype ($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   539
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   540
	$linkname = readlink $file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   541
	    if ($type == SYMLINK) && $symlinks;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   542
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   543
	$file = _munge_file ($file)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   544
	    if ($^O eq "MacOS");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   545
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   546
	return +{name => $file,		    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   547
		 mode => $mode,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   548
		 uid => $uid,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   549
		 gid => $gid,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   550
		 size => $size,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   551
		 mtime => (($mtime - $time_offset) | 0),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   552
		 chksum => "      ",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   553
		 type => $type, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   554
		 linkname => $linkname,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   555
		 magic => "ustar",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   556
		 version => "00",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   557
		 # WinNT protection
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   558
		 uname => ($fake_getpwuid || scalar getpwuid($uid)),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   559
		 gname => ($fake_getgrgid || scalar getgrgid ($gid)),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   560
		 devmajor => 0, # We don't handle this yet
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   561
		 devminor => 0, # We don't handle this yet
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   562
		 prefix => "",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   563
		 data => undef,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   564
		};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   565
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   566
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   567
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   568
sub _extract_file {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   569
    my ($entry, $handle) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   570
    my ($file, $cwd, @path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   571
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   572
    # For the moment, we assume that all paths in tarfiles
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   573
    # are given according to Unix standards.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   574
    # Which they *are*, according to the tar format spec!
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   575
    @path = split(/\//,$entry->{name});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   576
    $path[0] = '/' unless defined $path[0]; # catch absolute paths
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   577
    $file = pop @path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   578
    $file =~ s,:,/,g
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   579
	if $^O eq "MacOS";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   580
    $cwd = cwd
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   581
	if @path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   582
    foreach (@path) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   583
	if ($^O eq "MacOS") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   584
	    s,:,/,g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   585
	    $_ = "::" if $_ eq "..";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   586
	    $_ = ":" if $_ eq ".";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   587
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   588
	if (-e $_ && ! -d _) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   589
	    $^W && carp "$_ exists but is not a directory!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   590
	    next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   591
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   592
	mkdir $_, 0777 unless -d _;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   593
	chdir $_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   594
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   595
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   596
    if ($entry->{type} == FILE) {	# Ordinary file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   597
	sysopen (FH, $file, O_WRONLY|O_CREAT|O_TRUNC)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   598
	    and binmode FH
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   599
		or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   600
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   601
	if ($handle) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   602
	    my $size = $entry->{size};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   603
	    my $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   604
	    while ($size > 4096) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   605
		$handle->gzread ($data, 4096)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   606
		    and syswrite (FH, $data, length $data)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   607
			or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   608
		$size -= 4096;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   609
	    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   610
	    $handle->gzread ($data, $size)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   611
		and syswrite (FH, $data, length $data)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   612
		    or goto &_drat
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   613
			if ($size);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   614
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   615
	else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   616
	    syswrite FH, $entry->{data}, $entry->{size}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   617
		or goto &_drat
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   618
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   619
	close FH
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   620
	    or goto &_drat
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   621
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   622
    elsif ($entry->{type} == DIR) { # Directory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   623
	goto &_drat
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   624
	    if (-e $file && ! -d $file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   625
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   626
	mkdir $file,0777
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   627
	    unless -d $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   628
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   629
    elsif ($entry->{type} == UNKNOWN) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   630
	$error = "unknown file type: $_->{type}";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   631
	return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   632
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   633
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   634
	_make_special_file ($entry, $file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   635
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   636
    utime time, $entry->{mtime} + $time_offset, $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   637
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   638
    # We are root, and chown exists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   639
    chown $entry->{uid}, $entry->{gid}, $file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   640
	if ($> == 0 and $^O ne "MacOS" and $^O ne "MSWin32");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   641
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   642
    # chmod is done last, in case it makes file readonly
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   643
    # (this accomodates DOSish OSes)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   644
    chmod $entry->{mode}, $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   645
    chdir $cwd
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   646
	if @path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   647
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   648
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   649
###
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   650
### Methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   651
###
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   652
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   653
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   654
## Class methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   655
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   656
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   657
# Perfom the equivalent of ->new()->add_files(), ->write() without the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   658
# overhead of maintaining an Archive::Tar object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   659
sub create_archive {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   660
    my ($handle, $file, $compress) = splice (@_, 0, 3);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   661
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   662
    if ($compress && !$compression) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   663
	$error = "Compression not available.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   664
	return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   665
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   666
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   667
    $handle = gensym;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   668
    open $handle, ref ($file) ? ">&". fileno ($file) : ">" . $file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   669
	and binmode ($handle)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   670
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   671
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   672
    _write_tar (_get_handle ($handle, int ($compress)),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   673
		map {_add_file ($_)} @_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   674
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   675
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   676
# Perfom the equivalent of ->new()->list_files() without the overhead
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   677
# of maintaining an Archive::Tar object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   678
sub list_archive {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   679
    my ($handle, $file, $fields) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   680
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   681
    $handle = gensym;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   682
    open $handle, ref ($file) ? "<&". fileno ($file) : "<" . $file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   683
	and binmode ($handle)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   684
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   685
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   686
    my $data = _read_tar (_get_handle ($handle), 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   687
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   688
    return map {my %h; @h{@$fields} = @$_{@$fields}; \%h} @$data
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   689
        if (ref $fields eq 'ARRAY'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   690
	    && (@$fields > 1 || $fields->[0] ne 'name'));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   691
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   692
    return map {$_->{name}} @$data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   693
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   694
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   695
# Perform the equivalen of ->new()->extract() without the overhead of
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   696
# maintaining an Archive::Tar object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   697
sub extract_archive {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   698
    my ($handle, $file) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   699
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   700
    $handle = gensym;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   701
    open $handle, ref ($file) ? "<&". fileno ($file) : "<" . $file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   702
	and binmode ($handle)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   703
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   704
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   705
    _read_tar (_get_handle ($handle), 0, 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   706
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   707
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   708
# Constructor. Reads tarfile if given an argument that's the name of a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   709
# readable file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   710
sub new {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   711
    my ($class, $file) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   712
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   713
    my $self = bless {}, $class;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   714
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   715
    $self->read ($file)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   716
      if defined $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   717
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   718
    return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   719
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   720
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   721
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   722
# Read a tarfile. Returns number of component files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   723
sub read {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   724
    my ($self, $file) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   725
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   726
    $self->{_data} = [];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   727
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   728
    $self->{_handle} = gensym;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   729
    open $self->{_handle}, ref ($file) ? "<&". fileno ($file) : "<" . $file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   730
	and binmode ($self->{_handle})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   731
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   732
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   733
    $self->{_data} = _read_tar (_get_handle ($self->{_handle}), 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   734
				  sysseek $self->{_handle}, 0, 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   735
    return scalar @{$self->{_data}};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   736
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   737
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   738
# Write a tar archive to file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   739
sub write {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   740
    my ($self, $file, $compress) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   741
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   742
    return _format_tar_file (@{$self->{_data}})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   743
	unless (@_ > 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   744
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   745
    my $handle = gensym;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   746
    open $handle, ref ($file) ? ">&". fileno ($file) : ">" . $file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   747
	and binmode ($handle)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   748
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   749
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   750
    if ($compress && !$compression) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   751
	$error = "Compression not available.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   752
	return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   753
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   754
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   755
    _write_tar (_get_handle ($handle, $compress || 0), $self->{_data});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   756
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   757
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   758
# Add files to the archive. Returns number of successfully added files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   759
sub add_files {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   760
    my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   761
    my ($counter, $file, $entry);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   762
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   763
    foreach $file (@_) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   764
	if ($entry = _add_file ($file)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   765
	    push (@{$self->{'_data'}}, $entry);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   766
	    ++$counter;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   767
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   768
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   769
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   770
    return $counter;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   771
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   772
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   773
# Add data as a file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   774
sub add_data {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   775
    my ($self, $file, $data, $opt) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   776
    my $ref = {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   777
    my ($key);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   778
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   779
    if($^O eq "MacOS") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   780
	$file = _munge_file($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   781
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   782
    $ref->{'data'} = $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   783
    $ref->{name} = $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   784
    $ref->{mode} = 0666 & (0777 - umask);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   785
    $ref->{uid} = $>;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   786
    $ref->{gid} = (split(/ /,$)))[0]; # Yuck
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   787
    $ref->{size} = length $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   788
    $ref->{mtime} = ((time - $time_offset) | 0),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   789
    $ref->{chksum} = "      ";	# Utterly pointless
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   790
    $ref->{type} = FILE;		# Ordinary file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   791
    $ref->{linkname} = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   792
    $ref->{magic} = "ustar";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   793
    $ref->{version} = "00";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   794
    # WinNT protection
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   795
    $ref->{uname} = $fake_getpwuid || getpwuid ($>);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   796
    $ref->{gname} = $fake_getgrgid || getgrgid ($ref->{gid});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   797
    $ref->{devmajor} = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   798
    $ref->{devminor} = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   799
    $ref->{prefix} = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   800
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   801
    if ($opt) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   802
	foreach $key (keys %$opt) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   803
	    $ref->{$key} = $opt->{$key}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   804
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   805
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   806
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   807
    push (@{$self->{'_data'}}, $ref);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   808
    return 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   809
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   810
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   811
sub rename {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   812
    my ($self) = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   813
    my $entry;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   814
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   815
    foreach $entry (@{$self->{_data}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   816
	@{$self->{_data}} = grep {$_->{name} ne $entry} @{$self->{'_data'}};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   817
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   818
    return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   819
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   820
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   821
sub remove {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   822
    my ($self) = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   823
    my $entry;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   824
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   825
    foreach $entry (@_) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   826
	@{$self->{_data}} = grep {$_->{name} ne $entry} @{$self->{'_data'}};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   827
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   828
    return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   829
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   830
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   831
# Get the content of a file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   832
sub get_content {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   833
    my ($self, $file) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   834
    my ($entry, $data);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   835
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   836
    foreach $entry (@{$self->{_data}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   837
	next
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   838
	    unless $entry->{name} eq $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   839
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   840
	return $entry->{data}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   841
	    unless $entry->{offset};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   842
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   843
	my $handle = _get_handle ($self->{_handle});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   844
	$handle->gzseek ($entry->{offset}, 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   845
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   846
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   847
	$handle->gzread ($data, $entry->{size}) != -1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   848
	    or goto &_drat;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   849
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   850
	return $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   851
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   852
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   853
    return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   854
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   855
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   856
# Replace the content of a file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   857
sub replace_content {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   858
    my ($self, $file, $content) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   859
    my $entry;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   860
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   861
    foreach $entry (@{$self->{_data}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   862
	next
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   863
	    unless $entry->{name} eq $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   864
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   865
	$entry->{data} = $content;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   866
	$entry->{size} = length $content;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   867
	$entry->{offset} = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   868
	return 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   869
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   870
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   871
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   872
# Write a single (probably) file from the in-memory archive to disk
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   873
sub extract {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   874
    my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   875
    my @files = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   876
    my ($file, $entry);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   877
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   878
    @files = list_files ($self) unless @files;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   879
    foreach $entry (@{$self->{_data}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   880
	my $cnt = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   881
	foreach $file (@files) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   882
	    ++$cnt, next
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   883
		unless $entry->{name} eq $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   884
	    my $handle = $entry->{offset} && _get_handle ($self->{_handle});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   885
	    $handle->gzseek ($entry->{offset}, 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   886
		or goto &_drat
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   887
		    if $handle;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   888
	    _extract_file ($entry, $handle);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   889
	    splice (@_, $cnt, 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   890
	    last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   891
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   892
	last
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   893
	    unless @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   894
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   895
    $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   896
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   897
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   898
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   899
# Return a list names or attribute hashes for all files in the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   900
# in-memory archive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   901
sub list_files {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   902
 my ($self, $fields) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   903
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   904
    return map {my %h; @h{@$fields} = @$_{@$fields}; \%h} @{$self->{'_data'}}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   905
    if (ref $fields eq 'ARRAY' && (@$fields > 1 || $fields->[0] ne 'name'));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   906
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   907
    return map {$_->{name}} @{$self->{'_data'}}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   908
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   909
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   910
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   911
### Standard end of module :-)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   912
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   913
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   914
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   915
# Sub-package to hide I/O differences between compressed &
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   916
# uncompressed archives.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   917
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   918
# Yes, I could have used the IO::* class hierarchy here, but I'm
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   919
# trying to minimise the necessity for non-core modules on perl5
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   920
# environments < 5.004
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   921
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   922
package Archive::Tar::_io;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   923
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   924
sub gzseek {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   925
    sysseek $_[0], $_[1], $_[2];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   926
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   927
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   928
sub gzread {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   929
    sysread $_[0], $_[1], $_[2];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   930
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   931
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   932
sub gzwrite {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   933
    syswrite $_[0], $_[1], length $_[1];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   934
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   935
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   936
sub gzclose {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   937
    !close $_[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   938
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   939
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   940
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   941
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   942
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   943
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   944
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   945
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   946
Tar - module for manipulation of tar archives.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   947
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   948
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   949
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   950
  use Archive::Tar;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   951
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   952
  Archive::Tar->create_archive ("my.tar.gz", 9, "/this/file", "/that/file");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   953
  print join "\n", Archive::Tar->list_archive ("my.tar.gz"), "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   954
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   955
  $tar = Archive::Tar->new();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   956
  $tar->read("origin.tar.gz",1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   957
  $tar->add_files("file/foo.c", "file/bar.c");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   958
  $tar->add_data("file/baz.c","This is the file contents");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   959
  $tar->write("files.tar");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   960
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   961
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   962
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   963
This is a module for the handling of tar archives. 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   964
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   965
Archive::Tar provides an object oriented mechanism for handling tar
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   966
files.  It provides class methods for quick and easy files handling
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   967
while also allowing for the creation of tar file objects for custom
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   968
manipulation.  If you have the Compress::Zlib module installed,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   969
Archive::Tar will also support compressed or gzipped tar files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   970
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   971
=head2 Class Methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   972
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   973
The class methods should be sufficient for most tar file interaction.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   974
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   975
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   976
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   977
=item create_archive ($file, $compression, @filelist)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   978
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   979
Creates a tar file from the list of files provided.  The first
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   980
argument can either be the name of the tar file to create or a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   981
reference to an open file handle (e.g. a GLOB reference).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   982
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   983
The second argument specifies the level of compression to be used, if
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   984
any.  Compression of tar files requires the installation of the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   985
Compress::Zlib module.  Specific levels or compression may be
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   986
requested by passing a value between 2 and 9 as the second argument.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   987
Any other value evaluating as true will result in the default
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   988
compression level being used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   989
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   990
The remaining arguments list the files to be included in the tar file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   991
These files must all exist.  Any files which don\'t exist or can\'t be
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   992
read are silently ignored.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   993
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   994
If the archive creation fails for any reason, C<create_archive> will
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   995
return undef.  Please use the C<error> method to find the cause of the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   996
failure.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   997
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   998
=item list_archive ($file, ['property', 'property',...])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   999
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1000
=item list_archive ($file)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1001
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1002
Returns a list of the names of all the files in the archive.  The
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1003
first argument can either be the name of the tar file to create or a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1004
reference to an open file handle (e.g. a GLOB reference).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1005
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1006
If C<list_archive()> is passed an array reference as its second
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1007
argument it returns a list of hash references containing the requested
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1008
properties of each file.  The following list of properties is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1009
supported: name, size, mtime (last modified date), mode, uid, gid,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1010
linkname, uname, gname, devmajor, devminor, prefix.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1011
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1012
Passing an array reference containing only one element, 'name', is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1013
special cased to return a list of names rather than a list of hash
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1014
references.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1015
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1016
=item extract_archive ($file)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1017
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1018
Extracts the contents of the tar file.  The first argument can either
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1019
be the name of the tar file to create or a reference to an open file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1020
handle (e.g. a GLOB reference).  All relative paths in the tar file will
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1021
be created underneath the current working directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1022
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1023
If the archive extraction fails for any reason, C<extract_archive>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1024
will return undef.  Please use the C<error> method to find the cause
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1025
of the failure.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1026
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1027
=item new ($file)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1028
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1029
=item new ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1030
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1031
Returns a new Tar object. If given any arguments, C<new()> calls the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1032
C<read()> method automatically, parsing on the arguments provided L<read()>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1033
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1034
If C<new()> is invoked with arguments and the read method fails for
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1035
any reason, C<new()> returns undef.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1036
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1037
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1038
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1039
=head2 Instance Methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1040
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1041
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1042
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1043
=item read ($ref, $compressed)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1044
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1045
Read the given tar file into memory. The first argument can either be
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1046
the name of a file or a reference to an already open file handle (e.g. a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1047
GLOB reference).  The second argument indicates whether the file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1048
referenced by the first argument is compressed.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1049
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1050
The second argument is now optional as Archive::Tar will automatically
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1051
detect compressed archives.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1052
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1053
The C<read> will I<replace> any previous content in C<$tar>!
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1054
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1055
=item add_files(@filenamelist)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1056
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1057
Takes a list of filenames and adds them to the in-memory archive.  On
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1058
MacOS, the path to the file is automatically converted to a Unix like
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1059
equivalent for use in the archive, and the file\'s modification time
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1060
is converted from the MacOS epoch to the Unix epoch.  So tar archives
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1061
created on MacOS with B<Archive::Tar> can be read both with I<tar> on
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1062
Unix and applications like I<suntar> or I<Stuffit Expander> on MacOS.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1063
Be aware that the file\'s type/creator and resource fork will be lost,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1064
which is usually what you want in cross-platform archives.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1065
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1066
=item add_data ($filename, $data, $opthashref)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1067
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1068
Takes a filename, a scalar full of data and optionally a reference to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1069
a hash with specific options. Will add a file to the in-memory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1070
archive, with name C<$filename> and content C<$data>. Specific
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1071
properties can be set using C<$opthashref>, The following list of
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1072
properties is supported: name, size, mtime (last modified date), mode,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1073
uid, gid, linkname, uname, gname, devmajor, devminor, prefix.  (On
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1074
MacOS, the file\'s path and modification times are converted to Unix
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1075
equivalents.)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1076
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1077
=item remove (@filenamelist)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1078
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1079
Removes any entries with names matching any of the given filenames
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1080
from the in-memory archive. String comparisons are done with C<eq>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1081
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1082
=item write ($file, $compressed)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1083
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1084
Write the in-memory archive to disk.  The first argument can either be
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1085
the name of a file or a reference to an already open file handle (be a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1086
GLOB reference).  If the second argument is true, the module will use
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1087
Compress::Zlib to write the file in a compressed format.  If
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1088
Compress:Zlib is not available, the C<write> method will fail.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1089
Specific levels of compression can be chosen by passing the values 2
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1090
through 9 as the second parameter.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1091
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1092
If no arguments are given, C<write> returns the entire formatted
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1093
archive as a string, which could be useful if you\'d like to stuff the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1094
archive into a socket or a pipe to gzip or something.  This
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1095
functionality may be deprecated later, however, as you can also do
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1096
this using a GLOB reference for the first argument.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1097
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1098
=item extract(@filenames)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1099
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1100
Write files whose names are equivalent to any of the names in
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1101
C<@filenames> to disk, creating subdirectories as necessary. This
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1102
might not work too well under VMS.  Under MacPerl, the file\'s
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1103
modification time will be converted to the MacOS zero of time, and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1104
appropriate conversions will be done to the path.  However, the length
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1105
of each element of the path is not inspected to see whether it\'s
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1106
longer than MacOS currently allows (32 characters).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1107
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1108
If C<extract> is called without a list of file names, the entire
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1109
contents of the archive are extracted.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1110
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1111
=item list_files(['property', 'property',...])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1112
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1113
=item list_files()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1114
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1115
Returns a list of the names of all the files in the archive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1116
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1117
If C<list_files()> is passed an array reference as its first argument
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1118
it returns a list of hash references containing the requested
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1119
properties of each file.  The following list of properties is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1120
supported: name, size, mtime (last modified date), mode, uid, gid,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1121
linkname, uname, gname, devmajor, devminor, prefix.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1122
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1123
Passing an array reference containing only one element, 'name', is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1124
special cased to return a list of names rather than a list of hash
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1125
references.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1126
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1127
=item get_content($file)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1128
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1129
Return the content of the named file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1130
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1131
=item replace_content($file,$content)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1132
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1133
Make the string $content be the content for the file named $file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1134
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1135
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1136
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1137
=head1 CHANGES
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1138
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1139
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1140
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1141
=item Version 0.20
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1142
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1143
Added class methods for creation, extraction and listing of tar files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1144
No longer maintain a complete copy of the tar file in memory.  Removed
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1145
the C<data()> method.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1146
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1147
=item Version 0.10
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1148
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1149
Numerous changes. Brought source under CVS.  All changes now recorded
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1150
in ChangeLog file in distribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1151
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1152
=item Version 0.08
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1153
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1154
New developer/maintainer.  Calle has carpal-tunnel syndrome and cannot
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1155
type a great deal. Get better as soon as you can, Calle.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1156
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1157
Added proper support for MacOS.  Thanks to Paul J. Schinder
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1158
<schinder@leprss.gsfc.nasa.gov>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1159
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1160
=item Version 0.071
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1161
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1162
Minor release.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1163
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1164
Arrange to chmod() at the very end in case it makes the file read only.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1165
Win32 is actually picky about that.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1166
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1167
SunOS 4.x tar makes tarfiles that contain directory entries that
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1168
don\'t have typeflag set properly.  We use the trailing slash to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1169
recognise directories in such tar files.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1170
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1171
=item Version 0.07
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1172
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1173
Fixed (hopefully) broken portability to MacOS, reported by Paul J.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1174
Schinder at Goddard Space Flight Center.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1175
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1176
Fixed two bugs with symlink handling, reported in excellent detail by
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1177
an admin at teleport.com called Chris.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1178
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1179
Primitive tar program (called ptar) included with distribution. Usage
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1180
should be pretty obvious if you\'ve used a normal tar program.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1181
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1182
Added methods get_content and replace_content.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1183
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1184
Added support for paths longer than 100 characters, according to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1185
POSIX. This is compatible with just about everything except GNU tar.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1186
Way to go, GNU tar (use a better tar, or GNU cpio).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1187
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1188
NOTE: When adding files to an archive, files with basenames longer
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1189
      than 100 characters will be silently ignored. If the prefix part
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1190
      of a path is longer than 155 characters, only the last 155
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1191
      characters will be stored.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1192
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1193
=item Version 0.06
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1194
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1195
Added list_files() method, as requested by Michael Wiedman.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1196
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1197
Fixed a couple of dysfunctions when run under Windows NT. Michael
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1198
Wiedmann reported the bugs.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1199
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1200
Changed the documentation to reflect reality a bit better.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1201
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1202
Fixed bug in format_tar_entry. Bug reported by Michael Schilli.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1203
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1204
=item Version 0.05
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1205
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1206
Quoted lots of barewords to make C<use strict;> stop complaining under
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1207
perl version 5.003.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1208
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1209
Ties to L<Compress::Zlib> put in. Will warn if it isn\'t available.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1210
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1211
$tar->write() with no argument now returns the formatted archive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1212
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1213
=item Version 0.04
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1214
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1215
Made changes to write_tar so that Solaris tar likes the resulting
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1216
archives better.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1217
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1218
Protected the calls to readlink() and symlink(). AFAIK this module
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1219
should now run just fine on Windows NT.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1220
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1221
Add method to write a single entry to disk (extract)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1222
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1223
Added method to add entries entirely from scratch (add_data)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1224
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1225
Changed name of add() to add_file()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1226
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1227
All calls to croak() removed and replaced with returning undef and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1228
setting Tar::error.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1229
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1230
Better handling of tarfiles with garbage at the end.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1231
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1232
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1233
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1234
Archive::Tar is Copyright 1997 Calle Dybedahl. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1235
                Copyright 1998 Stephen Zander. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1236
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1237
It is currently developed by Stephen Zander <gibreel@pobox.com>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1238
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1239
This library is free software; you can redistribute it and/or modify
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1240
it under the same terms as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1241
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
  1242
=cut