dpkg-source.pl 39 KB

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