dpkg-source.pl 40 KB

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