dpkg-source.pl 39 KB

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