aboutsummaryrefslogtreecommitdiffstats
path: root/configure.ac
diff options
context:
space:
mode:
Diffstat (limited to 'configure.ac')
0 files changed, 0 insertions, 0 deletions
71'>71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
package packdrake;

use strict;
use vars qw($VERSION);

$VERSION = "0.04";

=head1 NAME

packdrake - Simple Archive Extractor/Builder

=head1 SYNOPSIS

    require packdrake;

    packdrake::cat_archive("/export/media/media_info/hdlist.cz",
                           "/export/media/media_info/hdlist2.cz");
    packdrake::list_archive("/tmp/modules.cz2");

    my $packer = new packdrake("/tmp/modules.cz2");
    $packer->extract_archive("/tmp", "file1.o", "file2.o");

    my $packer = packdrake::build_archive
        (\*STDIN, "/lib/modules", "/tmp/modules.cz2",
         400000, "bzip2", "bzip2 -d");
    my $packer = packdrake::build_archive
        (\*STDIN, "/export/media/media_info/hdlist.cz",
         400000, "gzip -9", "gzip -d");

=head1 DESCRIPTION

C<packdrake> is a very simple archive extractor and builder used by Mandrakesoft.

=head1 IMPLEMENTATION

uncompressing sheme is:
        | |
        | |                                        | |
 $off1 =|*| }                                      | |
        |*| }                               $off2 =|+| }
        |*| } $siz1   =>   'gzip/bzip2 -d'   =>    |+| } $siz2  => $filename
        |*| }                                      |+| }
        |*| }                                      | |
        | |                                        | |
        | |                                        | |
        | |
where %data has the following format:
  { 'filename' => [ 'f', $off1, $siz1, $off2, $siz2 ] }
except for symbolink link where it is:
  { 'filename_symlink' => [ 'l', $symlink_value ] }
and directory where it is only
  { 'filename_directory' => [ 'd' ] }
as you can see, there is no owner, group, filemode... an extension could be
made with 'F' (instead of 'f'), 'L' instead of 'l' for exemple.
we do not need them as it is used for DrakX for fast archive extraction and
owner/filemode is for user running only (ie root).

archive file contains concatenation of all bzip2'ed group of files whose
filenames are on input,
then a TOC (describing %data, concatenation of toc_line) follow and a
TOC_TRAILER for summary.

=head1 SEE ALSO

The packdrake command is a simple executable perl script using this module.

=head1 COPYRIGHT

Copyright (C) 2000-2004 Mandrakesoft <fpons@mandrakesoft.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

=cut

#- taken from DrakX common stuff, for conveniance and modified to match our expectation.
sub dirname { @_ == 1 or die "packdrake: usage: dirname <name>\n"; local $_ = shift; s|[^/]*/*\s*$||; s|(.)/*$|$1|; $_ || '.' }
sub basename { @_ == 1 or die "packdrake: usage: basename <name>\n"; local $_ = shift; s|/*\s*$||; s|.*/||; $_ }
sub mkdir_ {
    my $root = dirname $_[0];
    if (-e $root) {
	-d $root or die "packdrake: mkdir: error creating directory $_[0]: $root is a file and i won't delete it\n";
    } else {
	mkdir_($root);
    }
    -d $_[0] and return;
    mkdir $_[0], 0755 or die "packdrake: mkdir: error creating directory $_[0]: $!\n";
}
sub symlink_ { mkdir_ dirname($_[1]); unlink $_[1]; symlink $_[0], $_[1] }

#- for building an archive, returns the string containing the file and data associated.
sub build_toc_line {
    my ($file, $data) = @_;

    for ($data->[0]) {
	return(/l/ && pack("anna*", 'l', length($file), length($data->[1]), "$file$data->[1]") ||
	       /d/ && pack("ana*", 'd', length($file), $file) ||
	       /f/ && pack("anNNNNa*", 'f', length($file), @$data[1..4], $file) ||
	       die "packdrake: unknown extension $_\n");
    }
}

sub build_toc_trailer {
    my ($packer) = @_;

    #- 'cz[0' is toc_trailer header where 0 is version information, only 0 now.
    #- '0]cz' is toc_trailer trailer that match the corresponding header for information.
    pack "a4NNNNa40a4", ($packer->{header},
			 $packer->{toc_d_count}, $packer->{toc_l_count}, $packer->{toc_f_count},
			 $packer->{toc_str_size}, $packer->{uncompress},
			 $packer->{trailer});
}

#- degraded reading of toc at end of archive, do not check filelist.
sub read_toc_trailer {
    my ($packer, $file) = @_;
    my $toc_trailer;

    local *ARCHIVE;
    open ARCHIVE, "<$file" or die "packdrake: cannot open archive file $file\n";
    $packer->{archive} = $file;

    #- seek to end of file minus 64, size of trailer.
    #- read toc_trailer, check header/trailer for version 0.
    seek ARCHIVE, -64, 2;
    read ARCHIVE, $toc_trailer, 64 or die "packdrake: cannot read toc_trailer of archive file $file\n";
    @$packer{qw(header toc_d_count toc_l_count toc_f_count toc_str_size uncompress trailer)} =
      unpack "a4NNNNZ40a4", $toc_trailer;
    $packer->{header} eq 'cz[0' && $packer->{trailer} eq '0]cz' or die "packdrake: bad toc_trailer in archive file $file\n";

    close ARCHIVE;
}

#- read toc at end of archive.
sub read_toc {
    my ($packer, $file) = @_;
    my ($toc, $toc_trailer, $toc_size);
    my @toc_str;
    my @toc_data;

    local *ARCHIVE;
    open ARCHIVE, "<$file" or die "packdrake: cannot open archive file $file\n";
    $packer->{archive} = $file;

    #- seek to end of file minus 64, size of trailer.
    #- read toc_trailer, check header/trailer for version 0.
    seek ARCHIVE, -64, 2;
    read ARCHIVE, $toc_trailer, 64 or die "packdrake: cannot read toc_trailer of archive file $file\n";
    @$packer{qw(header toc_d_count toc_l_count toc_f_count toc_str_size uncompress trailer)} =
      unpack "a4NNNNZ40a4", $toc_trailer;
    $packer->{header} eq 'cz[0' && $packer->{trailer} eq '0]cz' or die "packdrake: bad toc_trailer in archive file $file\n";

    #- read toc, extract data hashes.
    $toc_size = $packer->{toc_str_size} + 16*$packer->{toc_f_count};
    seek ARCHIVE, -64-$toc_size, 2;

    #- read strings separated by \n, so this char cannot be inside filename, oops.
    read ARCHIVE, $toc, $packer->{toc_str_size} or die "packdrake: cannot read toc of archive file $file\n";
    @toc_str = split "\n", $toc;

    #- read data for file.
    read ARCHIVE, $toc, 16*$packer->{toc_f_count} or die "packdrake: cannot read toc of archive file $file\n";
    @toc_data = unpack "N" . 4*$packer->{toc_f_count}, $toc;

    close ARCHIVE;

    foreach (0..$packer->{toc_d_count}-1) {
	my $file = $toc_str[$_];
	push @{$packer->{files}}, $file;
	$packer->{data}{$file} = [ 'd' ];
    }
    foreach (0..$packer->{toc_l_count}-1) {
	my ($file, $symlink) = ($toc_str[$packer->{toc_d_count}+2*$_],
				$toc_str[$packer->{toc_d_count}+2*$_+1]);
	push @{$packer->{files}}, $file;
	$packer->{data}{$file} = [ 'l', $symlink ];
    }
    foreach (0..$packer->{toc_f_count}-1) {
	my $file = $toc_str[$packer->{toc_d_count}+2*$packer->{toc_l_count}+$_];
	push @{$packer->{files}}, $file;
	$packer->{data}{$file} = [ 'f', @toc_data[4*$_ .. 4*$_+3] ];
    }