dpkg-source.pl 39 KB

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