dpkg-source.pl 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. #! /usr/bin/perl
  2. my $dpkglibdir = ".";
  3. my $version = "1.3.0"; # This line modified by Makefile
  4. my @filesinarchive;
  5. my %dirincluded;
  6. my %notfileobject;
  7. my $fn;
  8. $diff_ignore_default_regexp = '(?:^|/).*~$|(?:^|/)\..*\.swp|DEADJOE|(?:/CVS|/RCS|/.deps)(?:$|/.*$)';
  9. $sourcestyle = 'X';
  10. $dscformat = "1.0";
  11. use POSIX;
  12. use POSIX qw (:errno_h :signal_h);
  13. use strict 'refs';
  14. push (@INC, $dpkglibdir);
  15. require 'controllib.pl';
  16. # Make sure patch doesn't get any funny ideas
  17. delete $ENV{'POSIXLY_CORRECT'};
  18. my @exit_handlers = ();
  19. sub exit_handler {
  20. &$_ foreach ( reverse @exit_handlers );
  21. exit(127);
  22. }
  23. $SIG{'INT'} = \&exit_handler;
  24. $SIG{'HUP'} = \&exit_handler;
  25. $SIG{'QUIT'} = \&exit_handler;
  26. sub usageversion {
  27. print STDERR
  28. "Debian dpkg-source $version. Copyright (C) 1996
  29. Ian Jackson and Klee Dienes. This is free software; see the GNU
  30. General Public Licence version 2 or later for copying conditions.
  31. There is NO warranty.
  32. Usage: dpkg-source -x <filename>.dsc
  33. dpkg-source -b <directory> [<orig-directory>|<orig-targz>|\'\']
  34. Build options: -c<controlfile> get control info from this file
  35. -l<changelogfile> get per-version info from this file
  36. -F<changelogformat> force change log format
  37. -V<name>=<value> set a substitution variable
  38. -T<varlistfile> read variables here, not debian/substvars
  39. -D<field>=<value> override or add a .dsc field and value
  40. -U<field> remove a field
  41. -W Turn certain errors into warnings.
  42. -E When -W is enabled, -E disables it.
  43. -sa auto select orig source (-sA is default)
  44. -i[<regexp>] filter out files to ignore diffs of.
  45. Defaults to: '$diff_ignore_default_regexp'
  46. -I<filename> filter out files when building tarballs.
  47. -sk use packed orig source (unpack & keep)
  48. -sp use packed orig source (unpack & remove)
  49. -su use unpacked orig source (pack & keep)
  50. -sr use unpacked orig source (pack & remove)
  51. -ss trust packed & unpacked orig src are same
  52. -sn there is no diff, do main tarfile only
  53. -sA,-sK,-sP,-sU,-sR like -sa,-sp,-sk,-su,-sr but may overwrite
  54. Extract options: -sp (default) leave orig source packed in current dir
  55. -sn do not copy original source to current dir
  56. -su unpack original source tree too
  57. General options: -h print this message
  58. ";
  59. }
  60. sub handleformat {
  61. local $fmt = shift;
  62. local $ourfmt = $dscformat;
  63. $fmt =~ s/(.*)\.\d*/$1/;
  64. $ourfmt =~ s/(.*)\.\d*/$1/;
  65. return ($fmt==$ourfmt);
  66. }
  67. $i = 100;
  68. grep ($fieldimps {$_} = $i--,
  69. qw (Format Source Version Binary Origin Maintainer Architecture
  70. Standards-Version Build-Depends Build-Depends-Indep Build-Conflicts
  71. Build-Conflicts-Indep));
  72. while (@ARGV && $ARGV[0] =~ m/^-/) {
  73. $_=shift(@ARGV);
  74. if (m/^-b$/) {
  75. &setopmode('build');
  76. } elsif (m/^-x$/) {
  77. &setopmode('extract');
  78. } elsif (m/^-s([akpursnAKPUR])$/) {
  79. $sourcestyle= $1;
  80. } elsif (m/^-c/) {
  81. $controlfile= $';
  82. } elsif (m/^-l/) {
  83. $changelogfile= $';
  84. } elsif (m/^-F([0-9a-z]+)$/) {
  85. $changelogformat=$1;
  86. } elsif (m/^-D([^\=:]+)[=:]/) {
  87. $override{$1}= $';
  88. } elsif (m/^-U([^\=:]+)$/) {
  89. $remove{$1}= 1;
  90. } elsif (m/^-i(.*)$/) {
  91. $diff_ignore_regexp = $1 ? $1 : $diff_ignore_default_regexp;
  92. } elsif (m/^-I(.+)$/) {
  93. push @tar_ignore, "--exclude=$1";
  94. } elsif (m/^-V(\w[-:0-9A-Za-z]*)[=:]/) {
  95. $substvar{$1}= $';
  96. } elsif (m/^-T/) {
  97. $varlistfile= $';
  98. } elsif (m/^-h$/) {
  99. &usageversion; exit(0);
  100. } elsif (m/^-W$/) {
  101. $warnable_error= 1;
  102. } elsif (m/^-E$/) {
  103. $warnable_error= 0;
  104. } elsif (m/^--$/) {
  105. last;
  106. } else {
  107. &usageerr("unknown option $_");
  108. }
  109. }
  110. defined($opmode) || &usageerr("need -x or -b");
  111. $SIG{'PIPE'} = 'DEFAULT';
  112. if ($opmode eq 'build') {
  113. $sourcestyle =~ y/X/A/;
  114. $sourcestyle =~ m/[akpursnAKPUR]/ ||
  115. &usageerr("source handling style -s$sourcestyle not allowed with -b");
  116. @ARGV || &usageerr("-b needs a directory");
  117. @ARGV<=2 || &usageerr("-b takes at most a directory and an orig source argument");
  118. $dir= shift(@ARGV);
  119. $dir= "./$dir" unless $dir =~ m:^/:; $dir =~ s,/*$,,;
  120. stat($dir) || &error("cannot stat directory $dir: $!");
  121. -d $dir || &error("directory argument $dir is not a directory");
  122. $changelogfile= "$dir/debian/changelog" unless defined($changelogfile);
  123. $controlfile= "$dir/debian/control" unless defined($controlfile);
  124. &parsechangelog;
  125. &parsecontrolfile;
  126. $f{"Format"}=$dscformat;
  127. $archspecific=0;
  128. for $_ (keys %fi) {
  129. $v= $fi{$_};
  130. if (s/^C //) {
  131. if (m/^Source$/i) { &setsourcepackage; }
  132. elsif (m/^(Standards-Version|Origin|Maintainer|Uploaders)$/i) { $f{$_}= $v; }
  133. elsif (m/^Build-(Depends|Conflicts)(-Indep)?$/i) { $f{$_}= $v; }
  134. elsif (s/^X[BC]*S[BC]*-//i) { $f{$_}= $v; }
  135. elsif (m/^(Section|Priority|Files|Bugs)$/i || m/^X[BC]+-/i) { }
  136. else { &unknown('general section of control info file'); }
  137. } elsif (s/^C(\d+) //) {
  138. $i=$1; $p=$fi{"C$i Package"};
  139. push(@binarypackages,$p) unless $packageadded{$p}++;
  140. if (m/^Architecture$/) {
  141. if ($v eq 'any') {
  142. @sourcearch= ('any');
  143. } elsif ($v eq 'all') {
  144. if (!@sourcearch || $sourcearch[0] eq 'all') {
  145. @sourcearch= ('all');
  146. } else {
  147. @sourcearch= ('any');
  148. }
  149. } else {
  150. if (grep($sourcearch[0] eq $_, 'any','all')) {
  151. @sourcearch= ('any');
  152. } else {
  153. for $a (split(/\s+/,$v)) {
  154. &error("architecture $a only allowed on its own".
  155. " (list for package $p is \`$a')")
  156. if grep($a eq $_, 'any','all');
  157. push(@sourcearch,$a) unless $archadded{$a}++;
  158. }
  159. }
  160. }
  161. $f{'Architecture'}= join(' ',@sourcearch);
  162. } elsif (s/^X[BC]*S[BC]*-//i) {
  163. $f{$_}= $v;
  164. } elsif (m/^(Package|Essential|Pre-Depends|Depends|Provides)$/i ||
  165. m/^(Recommends|Suggests|Optional|Conflicts|Replaces)$/i ||
  166. m/^(Description|Section|Priority)$/i ||
  167. m/^X[CS]+-/i) {
  168. } else {
  169. &unknown("package's section of control info file");
  170. }
  171. } elsif (s/^L //) {
  172. if (m/^Source$/) {
  173. &setsourcepackage;
  174. } elsif (m/^Version$/) {
  175. $f{$_}= $v;
  176. } elsif (s/^X[BS]*C[BS]*-//i) {
  177. $f{$_}= $v;
  178. } elsif (m/^(Maintainer|Changes|Urgency|Distribution|Date|Closes)$/i ||
  179. m/^X[BS]+-/i) {
  180. } else {
  181. &unknown("parsed version of changelog");
  182. }
  183. } else {
  184. &internerr("value from nowhere, with key >$_< and value >$v<");
  185. }
  186. }
  187. $f{'Binary'}= join(', ',@binarypackages);
  188. for $f (keys %override) { $f{&capit($f)}= $override{$f}; }
  189. for $f (qw(Version)) {
  190. defined($f{$f}) || &error("missing information for critical output field $f");
  191. }
  192. for $f (qw(Maintainer Architecture Standards-Version)) {
  193. defined($f{$f}) || &warn("missing information for output field $f");
  194. }
  195. defined($sourcepackage) || &error("unable to determine source package name !");
  196. $f{'Source'}= $sourcepackage;
  197. for $f (keys %remove) { delete $f{&capit($f)}; }
  198. $version= $f{'Version'};
  199. $version =~ s/^\d+://; $upstreamversion= $version; $upstreamversion =~ s/-[^-]*$//;
  200. $basenamerev= $sourcepackage.'_'.$version;
  201. $basename= $sourcepackage.'_'.$upstreamversion;
  202. $basedirname= $basename;
  203. $basedirname =~ s/_/-/;
  204. $origdir= "$dir.orig";
  205. $origtargz= "$basename.orig.tar.gz";
  206. if (@ARGV) {
  207. $origarg= shift(@ARGV);
  208. if (length($origarg)) {
  209. stat($origarg) || &error("cannot stat orig argument $origarg: $!");
  210. if (-d _) {
  211. $origdir= $origarg;
  212. $origdir= "./$origdir" unless $origdir =~ m,^/,; $origdir =~ s,/*$,,;
  213. $sourcestyle =~ y/aA/rR/;
  214. $sourcestyle =~ m/[ursURS]/ ||
  215. &error("orig argument is unpacked but source handling style".
  216. " -s$sourcestyle calls for packed (.orig.tar.gz)");
  217. } elsif (-f _) {
  218. $origtargz= $origarg;
  219. $sourcestyle =~ y/aA/pP/;
  220. $sourcestyle =~ m/[kpsKPS]/ ||
  221. &error("orig argument is packed but source handling style".
  222. " -s$sourcestyle calls for unpacked (.orig/)");
  223. } else {
  224. &error("orig argument $origarg is not a plain file or directory");
  225. }
  226. } else {
  227. $sourcestyle =~ y/aA/nn/;
  228. $sourcestyle =~ m/n/ ||
  229. &error("orig argument is empty (means no orig, no diff)".
  230. " but source handling style -s$sourcestyle wants something");
  231. }
  232. }
  233. if ($sourcestyle =~ m/[aA]/) {
  234. if (stat("$origtargz")) {
  235. -f _ || &error("packed orig \`$origtargz' exists but is not a plain file");
  236. $sourcestyle =~ y/aA/pP/;
  237. } elsif ($! != ENOENT) {
  238. &syserr("unable to stat putative packed orig \`$origtargz'");
  239. } elsif (stat("$origdir")) {
  240. -d _ || &error("unpacked orig \`$origdir' exists but is not a directory");
  241. $sourcestyle =~ y/aA/rR/;
  242. } elsif ($! != ENOENT) {
  243. &syserr("unable to stat putative unpacked orig \`$origdir'");
  244. } else {
  245. $sourcestyle =~ y/aA/nn/;
  246. }
  247. }
  248. $dirbase= $dir; $dirbase =~ s,/?$,,; $dirbase =~ s,[^/]+$,,; $dirname= $&;
  249. $dirname eq $basedirname || &warn("source directory \`$dir' is not <sourcepackage>".
  250. "-<upstreamversion> \`$basedirname'");
  251. if ($sourcestyle ne 'n') {
  252. $origdirbase= $origdir; $origdirbase =~ s,/?$,,;
  253. $origdirbase =~ s,[^/]+$,,; $origdirname= $&;
  254. $origdirname eq "$basedirname.orig" ||
  255. &warn(".orig directory name $origdirname is not <package>".
  256. "-<upstreamversion> (wanted $basedirname.orig)");
  257. $tardirbase= $origdirbase; $tardirname= $origdirname;
  258. $tarname= $origtargz;
  259. $tarname eq "$basename.orig.tar.gz" ||
  260. &warn(".orig.tar.gz name $tarname is not <package>_<upstreamversion>".
  261. ".orig.tar.gz (wanted $basename.orig.tar.gz)");
  262. } else {
  263. $tardirbase= $dirbase; $tardirname= $dirname;
  264. $tarname= "$basenamerev.tar.gz";
  265. }
  266. if ($sourcestyle =~ m/[nurUR]/) {
  267. if (stat($tarname)) {
  268. $sourcestyle =~ m/[nUR]/ ||
  269. &error("tarfile \`$tarname' already exists, not overwriting,".
  270. " giving up; use -sU or -sR to override");
  271. } elsif ($! != ENOENT) {
  272. &syserr("unable to check for existence of \`$tarname'");
  273. }
  274. print("$progname: building $sourcepackage in $tarname\n")
  275. || &syserr("write building tar message");
  276. &forkgzipwrite("$tarname.new");
  277. defined($c2= fork) || &syserr("fork for tar");
  278. if (!$c2) {
  279. chdir($tardirbase) || &syserr("chdir to above (orig) source $tardirbase");
  280. open(STDOUT,">&GZIP") || &syserr("reopen gzip for tar");
  281. # FIXME: put `--' argument back when tar is fixed
  282. exec('tar',@tar_ignore,'-cf','-',$tardirname); &syserr("exec tar");
  283. }
  284. close(GZIP);
  285. &reapgzip;
  286. $c2 == waitpid($c2,0) || &syserr("wait for tar");
  287. $? && !(WIFSIGNALED($c2) && WTERMSIG($c2) == SIGPIPE) && subprocerr("tar");
  288. rename("$tarname.new",$tarname) ||
  289. &syserr("unable to rename \`$tarname.new' (newly created) to \`$tarname'");
  290. } else {
  291. print("$progname: building $sourcepackage using existing $tarname\n")
  292. || &syserr("write using existing tar message");
  293. }
  294. addfile("$tarname");
  295. if ($sourcestyle =~ m/[kpKP]/) {
  296. if (stat($origdir)) {
  297. $sourcestyle =~ m/[KP]/ ||
  298. &error("orig dir \`$origdir' already exists, not overwriting,".
  299. " giving up; use -sA, -sK or -sP to override");
  300. push @exit_handlers, sub { erasedir($origdir) };
  301. erasedir($origdir);
  302. pop @exit_handlers;
  303. } elsif ($! != ENOENT) {
  304. &syserr("unable to check for existence of orig dir \`$origdir'");
  305. }
  306. $expectprefix= $origdir; $expectprefix =~ s,^\./,,;
  307. # tar checking is disabled, there are too many broken tar archives out there
  308. # which we can still handle anyway.
  309. # checktarsane($origtargz,$expectprefix);
  310. mkdir("$origtargz.tmp-nest",0755) ||
  311. &syserr("unable to create \`$origtargz.tmp-nest'");
  312. push @exit_handlers, sub { erasedir("$origtargz.tmp-nest") };
  313. extracttar($origtargz,"$origtargz.tmp-nest",$expectprefix);
  314. rename("$origtargz.tmp-nest/$expectprefix",$expectprefix) ||
  315. &syserr("unable to rename \`$origtargz.tmp-nest/$expectprefix' to ".
  316. "\`$expectprefix'");
  317. rmdir("$origtargz.tmp-nest") ||
  318. &syserr("unable to remove \`$origtargz.tmp-nest'");
  319. pop @exit_handlers;
  320. }
  321. if ($sourcestyle =~ m/[kpursKPUR]/) {
  322. print("$progname: building $sourcepackage in $basenamerev.diff.gz\n")
  323. || &syserr("write building diff message");
  324. &forkgzipwrite("$basenamerev.diff.gz");
  325. defined($c2= open(FIND,"-|")) || &syserr("fork for find");
  326. if (!$c2) {
  327. chdir($dir) || &syserr("chdir to $dir for find");
  328. exec('find','.','-print0'); &syserr("exec find");
  329. }
  330. $/= "\0";
  331. file:
  332. while (defined($fn= <FIND>)) {
  333. $fn =~ s/\0$//;
  334. next file if $fn =~ m/$diff_ignore_regexp/o;
  335. $fn =~ s,^\./,,;
  336. lstat("$dir/$fn") || &syserr("cannot stat file $dir/$fn");
  337. if (-l _) {
  338. $type{$fn}= 'symlink';
  339. &checktype('-l') || next;
  340. defined($n= readlink("$dir/$fn")) ||
  341. &syserr("cannot read link $dir/$fn");
  342. defined($n2= readlink("$origdir/$fn")) ||
  343. &syserr("cannot read orig link $origdir/$fn");
  344. $n eq $n2 || &unrepdiff2("symlink to $n2","symlink to $n");
  345. } elsif (-f _) {
  346. $type{$fn}= 'plain file';
  347. if (!lstat("$origdir/$fn")) {
  348. $! == ENOENT || &syserr("cannot stat orig file $origdir/$fn");
  349. $ofnread= '/dev/null';
  350. } elsif (-f _) {
  351. $ofnread= "$origdir/$fn";
  352. } else {
  353. &unrepdiff2("something else","plain file");
  354. next;
  355. }
  356. defined($c3= open(DIFFGEN,"-|")) || &syserr("fork for diff");
  357. if (!$c3) {
  358. $ENV{'LC_ALL'}= 'C';
  359. $ENV{'LANG'}= 'C';
  360. $ENV{'TZ'}= 'UTC0';
  361. exec('diff','-u',
  362. '-L',"$basedirname.orig/$fn",
  363. '-L',"$basedirname/$fn",
  364. '--',"$ofnread","$dir/$fn"); &syserr("exec diff");
  365. }
  366. $difflinefound= 0;
  367. $/= "\n";
  368. while (<DIFFGEN>) {
  369. if (m/^binary/i) {
  370. close(DIFFGEN); $/= "\0";
  371. &unrepdiff("binary file contents changed");
  372. next file;
  373. } elsif (m/^[-+\@ ]/) {
  374. $difflinefound=1;
  375. } elsif (m/^\\ No newline at end of file$/) {
  376. &warn("file $fn has no final newline ".
  377. "(either original or modified version)");
  378. } else {
  379. s/\n$//;
  380. &internerr("unknown line from diff -u on $fn: \`$_'");
  381. }
  382. print(GZIP $_) || &syserr("failed to write to gzip");
  383. }
  384. close(DIFFGEN); $/= "\0";
  385. if (WIFEXITED($?) && (($es=WEXITSTATUS($?))==0 || $es==1)) {
  386. if ($es==1 && !$difflinefound) {
  387. &unrepdiff("diff gave 1 but no diff lines found");
  388. }
  389. } else {
  390. subprocerr("diff on $dir/$fn");
  391. }
  392. } elsif (-p _) {
  393. $type{$fn}= 'pipe';
  394. &checktype('-p');
  395. } elsif (-b _ || -c _ || -S _) {
  396. &unrepdiff("device or socket is not allowed");
  397. } elsif (-d _) {
  398. $type{$fn}= 'directory';
  399. } else {
  400. &unrepdiff("unknown file type ($!)");
  401. }
  402. }
  403. close(FIND); $? && subprocerr("find on $dir");
  404. close(GZIP) || &syserr("finish write to gzip pipe");
  405. &reapgzip;
  406. defined($c2= open(FIND,"-|")) || &syserr("fork for 2nd find");
  407. if (!$c2) {
  408. chdir($origdir) || &syserr("chdir to $origdir for 2nd find");
  409. exec('find','.','-print0'); &syserr("exec 2nd find");
  410. }
  411. $/= "\0";
  412. while (defined($fn= <FIND>)) {
  413. $fn =~ s/\0$//;
  414. next if $fn =~ m/$diff_ignore_regexp/o;
  415. $fn =~ s,^\./,,;
  416. next if defined($type{$fn});
  417. lstat("$origdir/$fn") || &syserr("cannot check orig file $origdir/$fn");
  418. if (-f _) {
  419. &warn("ignoring deletion of file $fn");
  420. } elsif (-d _) {
  421. &warn("ignoring deletion of directory $fn");
  422. } elsif (-l _) {
  423. &warn("ignoring deletion of symlink $fn");
  424. } else {
  425. &unrepdiff2('not a file, directory or link','nonexistent');
  426. }
  427. }
  428. close(FIND); $? && subprocerr("find on $dirname");
  429. &addfile("$basenamerev.diff.gz");
  430. }
  431. if ($sourcestyle =~ m/[prPR]/) {
  432. erasedir($origdir);
  433. }
  434. print("$progname: building $sourcepackage in $basenamerev.dsc\n")
  435. || &syserr("write building message");
  436. open(STDOUT,"> $basenamerev.dsc") || &syserr("create $basenamerev.dsc");
  437. &outputclose(1);
  438. if ($ur) {
  439. print(STDERR "$progname: unrepresentable changes to source\n")
  440. || &syserr("write error msg: $!");
  441. exit(1);
  442. }
  443. exit(0);
  444. } else {
  445. $sourcestyle =~ y/X/p/;
  446. $sourcestyle =~ m/[pun]/ ||
  447. &usageerr("source handling style -s$sourcestyle not allowed with -x");
  448. @ARGV==1 || &usageerr("-x needs exactly one argument, the .dsc");
  449. $dsc= shift(@ARGV);
  450. $dsc= "./$dsc" unless $dsc =~ m:^/:;
  451. $dscdir= $dsc; $dscdir= "./$dscdir" unless $dsc =~ m,^/|^\./,;
  452. $dscdir =~ s,/[^/]+$,,;
  453. open(CDATA,"< $dsc") || &error("cannot open .dsc file $dsc: $!");
  454. &parsecdata('S',-1,"source control file $dsc");
  455. close(CDATA);
  456. for $f (qw(Source Version Files)) {
  457. defined($fi{"S $f"}) ||
  458. &error("missing critical source control field $f");
  459. }
  460. if (defined $fi{'S Format'}) {
  461. if (not handleformat($fi{'S Format'})) {
  462. &error("Unsupported format of .dsc file ($dscformat)");
  463. }
  464. $dscformat=$fi{'S Format'};
  465. }
  466. $sourcepackage =~ m/[^.0-9]/ &&
  467. &error("dsc format contains illegal character \`$&'");
  468. $sourcepackage= $fi{'S Source'};
  469. $sourcepackage =~ m/[^-+.0-9a-z]/ &&
  470. &error("source package name contains illegal character \`$&'");
  471. $sourcepackage =~ m/^[0-9a-z]./ ||
  472. &error("source package name is too short or starts with non-alphanum");
  473. $version= $fi{'S Version'};
  474. $version =~ m/[^-+:.0-9a-zA-Z~]/ &&
  475. &error("version number contains illegal character \`$&'");
  476. $version =~ s/^\d+://;
  477. if ($version =~ m/-([^-]+)$/) {
  478. $baseversion= $`; $revision= $1;
  479. } else {
  480. $baseversion= $version; $revision= '';
  481. }
  482. $files= $fi{'S Files'};
  483. for $file (split(/\n /,$files)) {
  484. next if $file eq '';
  485. $file =~ m/^([0-9a-f]{32})[ \t]+(\d+)[ \t]+([0-9a-zA-Z][-+:.,=0-9a-zA-Z_~]+)$/
  486. || &error("Files field contains bad line \`$file'");
  487. ($md5sum{$3},$size{$3},$file) = ($1,$2,$3);
  488. &setfile(\$tarfile) if $file =~ m/\.tar\.gz$/;
  489. &setfile(\$difffile) if $file =~ m/\.diff\.gz$/;
  490. }
  491. $newdirectory= $sourcepackage.'-'.$baseversion;
  492. $expectprefix= $newdirectory; $expectprefix.= '.orig' if length($difffile);
  493. length($tarfile) || &error("no tarfile in Files field");
  494. checkstats($tarfile);
  495. checkstats($difffile) if length($difffile);
  496. # tar checking is disabled, there are too many broken tar archives out there
  497. # which we can still handle anyway.
  498. # checktarsane("$dscdir/$tarfile",$expectprefix);
  499. if (length($difffile)) {
  500. &forkgzipread("$dscdir/$difffile");
  501. $/="\n";
  502. $_ = <GZIP>;
  503. while ($_ || !eof(GZIP)) {
  504. # read file header (---/+++ pair)
  505. s/\n$// or &error("diff is missing trailing newline");
  506. /^--- / or &error("expected ^--- in line $. of diff");
  507. $fn= $';
  508. substr($fn,0,length($expectprefix)+1) eq "$expectprefix/" ||
  509. &error("diff patches file ($fn) not in expected subdirectory");
  510. $fn =~ m/\.dpkg-orig$/ &&
  511. &error("diff patches file with name ending .dpkg-orig");
  512. $dirname= $fn;
  513. if ($dirname =~ s,/[^/]+$,, && !defined($dirincluded{$dirname})) {
  514. $dirtocreate{$dirname} = 1;
  515. }
  516. defined($notfileobject{$fn}) &&
  517. &error("diff patches something which is not a plain file");
  518. $_= <GZIP>; s/\n$// ||
  519. &error("diff finishes in middle of ---/+++ (line $.)");
  520. $_ eq '+++ '.$newdirectory.substr($fn,length($expectprefix)) ||
  521. &error("line after --- for file $fn isn't as expected");
  522. $filepatched{$fn}++ && &error("diff patches file $fn twice");
  523. # read hunks
  524. my $hunk = 0;
  525. while (($_ = <GZIP>) && !/^--- /) {
  526. # read hunk header (@@)
  527. s/\n$// or &error("diff is missing trailing newline");
  528. next if /^\\ No newline/;
  529. /^@@ -\d+(,(\d+))? \+\d+(,(\d+))? @\@$/ or
  530. &error("Expected ^@@ in line $. of diff");
  531. my ($olines, $nlines) = ($1 ? $2 : 1, $3 ? $4 : 1);
  532. ++$hunk;
  533. # read hunk
  534. while ($olines || $nlines) {
  535. $_ = <GZIP> or &error("unexpected end of diff");
  536. s/\n$// or &error("diff is missing trailing newline");
  537. next if /^\\ No newline/;
  538. if (/^ /) { --$olines; --$nlines; }
  539. elsif (/^-/) { --$olines; }
  540. elsif (/^\+/) { --$nlines; }
  541. else { &error("expected [ +-] at start of line $. of diff"); }
  542. }
  543. }
  544. $hunk or &error("expected ^\@\@ at line $. of diff");
  545. }
  546. close(GZIP);
  547. &reapgzip;
  548. }
  549. print("$progname: extracting $sourcepackage in $newdirectory\n")
  550. || &syserr("write extracting message");
  551. &erasedir($newdirectory);
  552. &erasedir("$newdirectory.orig");
  553. mkdir("$expectprefix.tmp-nest",0755)
  554. || &syserr("unable to create \`$expectprefix.tmp-nest'");
  555. system "chmod", "g-s", "$expectprefix.tmp-nest";
  556. extracttar("$dscdir/$tarfile","$expectprefix.tmp-nest","$expectprefix");
  557. rename("$expectprefix.tmp-nest/$expectprefix","$expectprefix")
  558. || &syserr("unable to rename \`$expectprefix.tmp-nest/$expectprefix' "
  559. ."to \`$expectprefix'");
  560. rmdir("$expectprefix.tmp-nest")
  561. || &syserr("unable to remove \`$expectprefix.tmp-nest'");
  562. for $dircreate (keys %dirtocreate) {
  563. $dircreatem= "";
  564. for $dircreatep (split("/",$dirc)) {
  565. $dircreatem.= $dircreatep;
  566. if (!lstat($dircreatem)) {
  567. $! == ENOENT || &syserr("cannot stat $dircreatem");
  568. mkdir($dircreatem,0777)
  569. || &syserr("failed to create $dircreatem subdirectory");
  570. }
  571. else {
  572. -d _ || &error("diff patches file in directory \`$dircreate',"
  573. ." but $dircreatem isn't a directory !");
  574. }
  575. }
  576. }
  577. if (length($difffile)) {
  578. rename($expectprefix,$newdirectory) ||
  579. &syserr("failed to rename newly-extracted $expectprefix to $newdirectory");
  580. if ($sourcestyle =~ m/u/) {
  581. mkdir("$expectprefix.tmp-nest",0755)
  582. || &syserr("unable to create \`$expectprefix.tmp-nest'");
  583. system "chmod", "g-s", "$expectprefix.tmp-nest";
  584. extracttar("$dscdir/$tarfile","$expectprefix.tmp-nest",
  585. "$expectprefix");
  586. rename("$expectprefix.tmp-nest/$expectprefix","$expectprefix")
  587. || &syserr("unable to rename \`$expectprefix.tmp-nest/"
  588. ."$expectprefix' to \`$expectprefix'");
  589. rmdir("$expectprefix.tmp-nest")
  590. || &syserr("unable to remove \`$expectprefix.tmp-nest'");
  591. } elsif ($sourcestyle =~ m/p/) {
  592. stat("$dscdir/$tarfile") ||
  593. &syserr("failed to stat \`$dscdir/$tarfile' to see if need to copy");
  594. ($dsctardev,$dsctarino) = stat _;
  595. $dumptar= $sourcepackage.'_'.$baseversion.'.orig.tar.gz';
  596. if (!stat($dumptar)) {
  597. $! == ENOENT || &syserr("failed to check destination \`$dumptar'".
  598. " to see if need to copy");
  599. } else {
  600. ($dumptardev,$dumptarino) = stat _;
  601. if ($dumptardev == $dsctardev && $dumptarino == $dsctarino) {
  602. $dumptar= '';
  603. }
  604. }
  605. if (length($dumptar)) {
  606. system('cp','--',"$dscdir/$tarfile","$dumptar");
  607. $? && subprocerr("cp $dscdir/$tarfile to $dumptar");
  608. }
  609. }
  610. &forkgzipread("$dscdir/$difffile");
  611. defined($c2= fork) || &syserr("fork for patch");
  612. if (!$c2) {
  613. open(STDIN,"<&GZIP") || &syserr("reopen gzip for patch");
  614. chdir($newdirectory) || &syserr("chdir to $newdirectory for patch");
  615. $ENV{'LC_ALL'}= 'C';
  616. $ENV{'LANG'}= 'C';
  617. exec('patch','-s','-t','-F','0','-N','-p1','-u',
  618. '-V','never','-g0','-b','-z','.dpkg-orig');
  619. &syserr("exec patch");
  620. }
  621. close(GZIP);
  622. $c2 == waitpid($c2,0) || &syserr("wait for patch");
  623. $? && subprocerr("patch");
  624. &reapgzip;
  625. for $fn (keys %filepatched) {
  626. $ftr= "$newdirectory/".substr($fn,length($expectprefix)+1).".dpkg-orig";
  627. unlink($ftr) || &syserr("remove patch backup file $ftr");
  628. }
  629. if (!(@s= lstat("$newdirectory/debian/rules"))) {
  630. $! == ENOENT || &syserr("cannot stat $newdirectory/debian/rules");
  631. &warn("$newdirectory/debian/rules does not exist");
  632. } elsif (-f _) {
  633. chmod($s[2] | 0111, "$newdirectory/debian/rules") ||
  634. &syserr("cannot make $newdirectory/debian/rules executable");
  635. } else {
  636. &warn("$newdirectory/debian/rules is not a plain file");
  637. }
  638. }
  639. $execmode= 0777 & ~umask;
  640. (@s= stat('.')) || &syserr("cannot stat \`.'");
  641. $dirmode= $execmode | ($s[2] & 02000);
  642. $plainmode= $execmode & ~0111;
  643. $fifomode= ($plainmode & 0222) | (($plainmode & 0222) << 1);
  644. for $fn (@filesinarchive) {
  645. $fn=~ s,^$expectprefix,$newdirectory,;
  646. (@s= lstat($fn)) || &syserr("cannot stat extracted object \`$fn'");
  647. $mode= $s[2];
  648. if (-d _) {
  649. $newmode= $dirmode;
  650. } elsif (-f _) {
  651. $newmode= ($mode & 0111) ? $execmode : $plainmode;
  652. } elsif (-p _) {
  653. $newmode= $fifomode;
  654. } elsif (!-l _) {
  655. &internerr("unknown object \`$fn' after extract (mode ".
  656. sprintf("0%o",$mode).")");
  657. } else { next; }
  658. next if ($mode & 07777) == $newmode;
  659. chmod($newmode,$fn) ||
  660. &syserr(sprintf("cannot change mode of \`%s' to 0%o from 0%o",
  661. $fn,$newmode,$mode));
  662. }
  663. exit(0);
  664. }
  665. sub checkstats {
  666. my ($f) = @_;
  667. my @s;
  668. my $m;
  669. open(STDIN,"< $dscdir/$f") || &syserr("cannot read $dscdir/$f");
  670. (@s= stat(STDIN)) || &syserr("cannot fstat $dscdir/$f");
  671. $s[7] == $size{$f} || &error("file $f has size $s[7] instead of expected $size{$f}");
  672. $m= `md5sum`; $? && subprocerr("md5sum $f"); $m =~ s/\n$//;
  673. $m =~ s/ *-$//; # Remove trailing spaces and -, to work with GNU md5sum
  674. $m =~ m/^[0-9a-f]{32}$/ || &failure("md5sum of $f gave bad output \`$m'");
  675. $m eq $md5sum{$f} || &error("file $f has md5sum $m instead of expected $md5sum{$f}");
  676. open(STDIN,"</dev/null") || &syserr("reopen stdin from /dev/null");
  677. }
  678. sub erasedir {
  679. my ($dir) = @_;
  680. if (!lstat($dir)) {
  681. $! == ENOENT && return;
  682. &syserr("cannot stat directory $dir (before removal)");
  683. }
  684. system 'rm','-rf','--',$dir;
  685. $? && subprocerr("rm -rf $dir");
  686. if (!stat($dir)) {
  687. $! == ENOENT && return;
  688. &syserr("unable to check for removal of dir \`$dir'");
  689. }
  690. &failure("rm -rf failed to remove \`$dir'");
  691. }
  692. use strict 'vars';
  693. sub checktarcpio {
  694. my ($tarfileread, $wpfx) = @_;
  695. my ($tarprefix, $c2);
  696. @filesinarchive = ();
  697. # make <CPIO> read from the uncompressed archive file
  698. &forkgzipread ("$tarfileread");
  699. if (! defined ($c2 = open (CPIO,"-|"))) { &syserr ("fork for cpio"); }
  700. if (!$c2) {
  701. $ENV{'LC_ALL'}= 'C';
  702. $ENV{'LANG'}= 'C';
  703. open (STDIN,"<&GZIP") || &syserr ("reopen gzip for cpio");
  704. &cpiostderr;
  705. exec ('cpio','-0t');
  706. &syserr ("exec cpio");
  707. }
  708. close (GZIP);
  709. $/ = "\0";
  710. while (defined ($fn = <CPIO>)) {
  711. $fn =~ s/\0$//;
  712. # store printable name of file for error messages
  713. my $pname = $fn;
  714. $pname =~ y/ -~/?/c;
  715. if ($fn =~ m/\n/) {
  716. &error ("tarfile \`$tarfileread' contains object with".
  717. " newline in its name ($pname)");
  718. }
  719. next if ($fn eq '././@LongLink');
  720. if (! $tarprefix) {
  721. if ($fn =~ m/\n/) {
  722. &error("first output from cpio -0t (from \`$tarfileread') ".
  723. "contains newline - you probably have an out of ".
  724. "date version of cpio. GNU cpio 2.4.2-2 is known to work");
  725. }
  726. $tarprefix = ($fn =~ m,((\./)*[^/]*)[/],)[0];
  727. # need to check for multiple dots on some operating systems
  728. # empty tarprefix (due to regex failer) will match emptry string
  729. if ($tarprefix =~ /^[.]*$/) {
  730. &error("tarfile \`$tarfileread' does not extract into a ".
  731. "directory off the current directory ($tarprefix from $pname)");
  732. }
  733. }
  734. my $fprefix = substr ($fn, 0, length ($tarprefix));
  735. my $slash = substr ($fn, length ($tarprefix), 1);
  736. if ((($slash ne '/') && ($slash ne '')) || ($fprefix ne $tarprefix)) {
  737. &error ("tarfile \`$tarfileread' contains object ($pname) ".
  738. "not in expected directory ($tarprefix)");
  739. }
  740. # need to check for multiple dots on some operating systems
  741. if ($fn =~ m/[.]{2,}/) {
  742. &error ("tarfile \`$tarfileread' contains object with".
  743. " /../ in its name ($pname)");
  744. }
  745. push (@filesinarchive, $fn);
  746. }
  747. close (CPIO);
  748. $? && subprocerr ("cpio");
  749. &reapgzip;
  750. $/= "\n";
  751. my $tarsubst = quotemeta ($tarprefix);
  752. return $tarprefix;
  753. }
  754. sub checktarsane {
  755. my ($tarfileread, $wpfx) = @_;
  756. my ($c2);
  757. %dirincluded = ();
  758. %notfileobject = ();
  759. my $tarprefix = &checktarcpio ($tarfileread, $wpfx);
  760. # make <TAR> read from the uncompressed archive file
  761. &forkgzipread ("$tarfileread");
  762. if (! defined ($c2 = open (TAR,"-|"))) { &syserr ("fork for tar -t"); }
  763. if (! $c2) {
  764. $ENV{'LC_ALL'}= 'C';
  765. $ENV{'LANG'}= 'C';
  766. open (STDIN, "<&GZIP") || &syserr ("reopen gzip for tar -t");
  767. exec ('tar', '-vvtf', '-'); &syserr ("exec tar -vvtf -");
  768. }
  769. close (GZIP);
  770. my $efix= 0;
  771. while (<TAR>) {
  772. chomp;
  773. if (! m,^(\S{10})\s,) {
  774. &error("tarfile \`$tarfileread' contains unknown object ".
  775. "listed by tar as \`$_'");
  776. }
  777. my $mode = $1;
  778. $mode =~ s/^([-dpsl])// ||
  779. &error("tarfile \`$tarfileread' contains object \`$fn' with ".
  780. "unknown or forbidden type \`".substr($_,0,1)."'");
  781. my $type = $&;
  782. if ($mode =~ /^l/) { $_ =~ s/ -> .*//; }
  783. s/ link to .+//;
  784. my @tarfields = split(' ', $_, 6);
  785. if (@tarfields < 6) {
  786. &error ("tarfile \`$tarfileread' contains incomplete entry \`$_'\n");
  787. }
  788. my $tarfn = deoctify ($tarfields[5]);
  789. # store printable name of file for error messages
  790. my $pname = $tarfn;
  791. $pname =~ y/ -~/?/c;
  792. # fetch name of file as given by cpio
  793. $fn = $filesinarchive[$efix++];
  794. my $l = length($fn);
  795. if (substr ($tarfn, 0, $l + 4) eq "$fn -> ") {
  796. # This is a symlink, as listed by tar. cpio doesn't
  797. # give us the targets of the symlinks, so we ignore this.
  798. $tarfn = substr($tarfn, 0, $l);
  799. }
  800. if ($tarfn ne $fn) {
  801. if ((length ($fn) == 99) && (length ($tarfn) >= 99)
  802. && (substr ($fn, 0, 99) eq substr ($tarfn, 0, 99))) {
  803. # this file doesn't match because cpio truncated the name
  804. # to the first 100 characters. let it slide for now.
  805. &warn ("filename \`$pname' was truncated by cpio;" .
  806. " unable to check full pathname");
  807. # Since it didn't match, later checks will not be able
  808. # to stat this file, so we replace it with the filename
  809. # fetched from tar.
  810. $filesinarchive[$efix-1] = $tarfn;
  811. } else {
  812. &error ("tarfile \`$tarfileread' contains unexpected object".
  813. " listed by tar as \`$_'; expected \`$pname'");
  814. }
  815. }
  816. # if cpio truncated the name above,
  817. # we still can't allow files to expand into /../
  818. # need to check for multiple dots on some operating systems
  819. if ($tarfn =~ m/[.]{2,}/) {
  820. &error ("tarfile \`$tarfileread' contains object with".
  821. "/../ in its name ($pname)");
  822. }
  823. if ($tarfn =~ /\.dpkg-orig$/) {
  824. &error ("tarfile \`$tarfileread' contains file with name ending in .dpkg-orig");
  825. }
  826. if ($mode =~ /[sStT]/ && $type ne 'd') {
  827. &error ("tarfile \`$tarfileread' contains setuid, setgid".
  828. " or sticky object \`$pname'");
  829. }
  830. if ($tarfn eq "$tarprefix/debian" && $type ne 'd') {
  831. &error ("tarfile \`$tarfileread' contains object \`debian'".
  832. " that isn't a directory");
  833. }
  834. if ($type eq 'd') { $tarfn =~ s,/$,,; }
  835. $tarfn =~ s,(\./)*,,;
  836. my $dirname = $tarfn;
  837. if (($dirname =~ s,/[^/]+$,,) && (! defined ($dirincluded{$dirname}))) {
  838. &warnerror ("tarfile \`$tarfileread' contains object \`$pname' but its containing ".
  839. "directory \`$dirname' does not precede it");
  840. $dirincluded{$dirname} = 1;
  841. }
  842. if ($type eq 'd') { $dirincluded{$tarfn} = 1; }
  843. if ($type ne '-') { $notfileobject{$tarfn} = 1; }
  844. }
  845. close (TAR);
  846. $? && subprocerr ("tar -vvtf");
  847. &reapgzip;
  848. my $tarsubst = quotemeta ($tarprefix);
  849. @filesinarchive = map { s/^$tarsubst/$wpfx/; $_ } @filesinarchive;
  850. %dirincluded = map { s/^$tarsubst/$wpfx/; $_=>1 } (keys %dirincluded);
  851. %notfileobject = map { s/^$tarsubst/$wpfx/; $_=>1 } (keys %notfileobject);
  852. }
  853. no strict 'vars';
  854. sub extracttar {
  855. my ($tarfileread,$dirchdir,$newtopdir) = @_;
  856. &forkgzipread("$tarfileread");
  857. defined($c2= fork) || &syserr("fork for tar -xkf -");
  858. if (!$c2) {
  859. open(STDIN,"<&GZIP") || &syserr("reopen gzip for tar -xkf -");
  860. &cpiostderr;
  861. chdir("$dirchdir") || &syserr("cannot chdir to \`$dirchdir' for tar extract");
  862. exec('tar','-xkf','-'); &syserr("exec tar -xkf -");
  863. }
  864. close(GZIP);
  865. $c2 == waitpid($c2,0) || &syserr("wait for tar -xkf -");
  866. $? && subprocerr("tar -xkf -");
  867. &reapgzip;
  868. opendir(D,"$dirchdir") || &syserr("Unable to open dir $dirchdir");
  869. @dirchdirfiles = grep($_ ne "." && $_ ne "..",readdir(D));
  870. closedir(D) || &syserr("Unable to close dir $dirchdir");
  871. if (@dirchdirfiles==1 && -d "$dirchdir/$dirchdirfiles[0]") {
  872. rename("$dirchdir/$dirchdirfiles[0]", "$dirchdir/$newtopdir") ||
  873. &syserr("Unable to rename $dirchdir/$dirchdirfiles[0] to ".
  874. "$dirchdir/$newtopdir");
  875. } else {
  876. mkdir("$dirchdir/$newtopdir", 0777) ||
  877. &syserr("Unable to mkdir $dirchdir/$newtopdir");
  878. for (@dirchdirfiles) {
  879. rename("$dirchdir/$_", "$dirchdir/$newtopdir/$_") ||
  880. &syserr("Unable to rename $dirchdir/$_ to ".
  881. "$dirchdir/$newtopdir/$_");
  882. }
  883. }
  884. }
  885. sub cpiostderr {
  886. open(STDERR,"| egrep -v '^[0-9]+ blocks\$' >&2") ||
  887. &syserr("reopen stderr for tar to grep out blocks message");
  888. }
  889. sub setfile {
  890. my ($varref) = @_;
  891. if (defined ($$varref)) {
  892. &error ("repeated file type - files " . $$varref . " and $file");
  893. }
  894. $$varref = $file;
  895. }
  896. sub checktype {
  897. if (!lstat("$origdir/$fn")) {
  898. &unrepdiff2("nonexistent",$type{$fn});
  899. } else {
  900. $v= eval("$_[0] _ ? 2 : 1"); $v || &internerr("checktype $@ ($_[0])");
  901. return 1 if $v == 2;
  902. &unrepdiff2("something else",$type{$fn});
  903. }
  904. return 0;
  905. }
  906. sub setopmode {
  907. defined($opmode) && &usageerr("only one of -x or -b allowed, and only once");
  908. $opmode= $_[0];
  909. }
  910. sub unrepdiff {
  911. print(STDERR "$progname: cannot represent change to $fn: $_[0]\n")
  912. || &syserr("write syserr unrep");
  913. $ur++;
  914. }
  915. sub unrepdiff2 {
  916. print(STDERR "$progname: cannot represent change to $fn:\n".
  917. "$progname: new version is $_[1]\n".
  918. "$progname: old version is $_[0]\n")
  919. || &syserr("write syserr unrep");
  920. $ur++;
  921. }
  922. sub forkgzipwrite {
  923. open(GZIPFILE,"> $_[0]") || &syserr("create file $_[0]");
  924. pipe(GZIPREAD,GZIP) || &syserr("pipe for gzip");
  925. defined($cgz= fork) || &syserr("fork for gzip");
  926. if (!$cgz) {
  927. open(STDIN,"<&GZIPREAD") || &syserr("reopen gzip pipe"); close(GZIPREAD);
  928. close(GZIP); open(STDOUT,">&GZIPFILE") || &syserr("reopen tar.gz");
  929. exec('gzip','-9'); &syserr("exec gzip");
  930. }
  931. close(GZIPREAD);
  932. $gzipsigpipeok= 0;
  933. }
  934. sub forkgzipread {
  935. local $SIG{PIPE} = 'DEFAULT';
  936. open(GZIPFILE,"< $_[0]") || &syserr("read file $_[0]");
  937. pipe(GZIP,GZIPWRITE) || &syserr("pipe for gunzip");
  938. defined($cgz= fork) || &syserr("fork for gunzip");
  939. if (!$cgz) {
  940. open(STDOUT,">&GZIPWRITE") || &syserr("reopen gunzip pipe"); close(GZIPWRITE);
  941. close(GZIP); open(STDIN,"<&GZIPFILE") || &syserr("reopen input file");
  942. exec('gunzip'); &syserr("exec gunzip");
  943. }
  944. close(GZIPWRITE);
  945. $gzipsigpipeok= 1;
  946. }
  947. sub reapgzip {
  948. $cgz == waitpid($cgz,0) || &syserr("wait for gzip");
  949. !$? || ($gzipsigpipeok && WIFSIGNALED($?) && WTERMSIG($?)==SIGPIPE) ||
  950. subprocerr("gzip");
  951. close(GZIPFILE);
  952. }
  953. sub addfile {
  954. my ($filename)= @_;
  955. stat($filename) || &syserr("could not stat output file \`$filename'");
  956. $size= (stat _)[7];
  957. my $md5sum= `md5sum <$filename`;
  958. $? && &subprocerr("md5sum $filename");
  959. $md5sum =~ s/^([0-9a-f]{32})\s*-?\s*\n$/$1/ || &failure("md5sum gave bogus output \`$_'");
  960. $f{'Files'}.= "\n $md5sum $size $filename";
  961. }
  962. # replace \ddd with their corresponding character, refuse \ddd > \377
  963. # modifies $_ (hs)
  964. {
  965. my $backslash;
  966. sub deoctify {
  967. my $fn= $_[0];
  968. $backslash= sprintf("\\%03o", unpack("C", "\\")) if !$backslash;
  969. s/\\{2}/$backslash/g;
  970. @_= split(/\\/, $fn);
  971. foreach (@_) {
  972. /^(\d{3})/ or next;
  973. &failure("bogus character `\\$1' in `$fn'\n") if oct($1) > 255;
  974. $_= pack("c", oct($1)) . $';
  975. }
  976. return join("", @_);
  977. } }