dpkg-source.pl 39 KB

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