build.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /*
  2. * dpkg-deb - construction and deconstruction of *.deb archives
  3. * build.c - building archives
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2000,2001 Wichert Akkerman <wakkerma@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2,
  11. * or (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with dpkg; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <config.h>
  23. #include <compat.h>
  24. #include <dpkg/i18n.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #include <signal.h>
  29. #include <sys/stat.h>
  30. #include <sys/types.h>
  31. #include <sys/wait.h>
  32. #include <time.h>
  33. #include <errno.h>
  34. #include <unistd.h>
  35. #include <dirent.h>
  36. #include <limits.h>
  37. #include <ctype.h>
  38. #include <assert.h>
  39. #ifdef WITH_ZLIB
  40. #include <zlib.h>
  41. #endif
  42. #include <dpkg/dpkg.h>
  43. #include <dpkg/dpkg-db.h>
  44. #include <dpkg/path.h>
  45. #include <dpkg/buffer.h>
  46. #include <dpkg/subproc.h>
  47. #include <dpkg/myopt.h>
  48. #include "dpkg-deb.h"
  49. #ifndef S_ISLNK
  50. # define S_ISLNK(mode) ((mode&0xF000) == S_IFLNK)
  51. #endif
  52. /* Simple structure to store information about a file.
  53. */
  54. struct file_info {
  55. struct file_info *next;
  56. struct stat st;
  57. char* fn;
  58. };
  59. static const char *arbitrary_fields[] = {
  60. "Package-Type",
  61. "Subarchitecture",
  62. "Kernel-Version",
  63. "Installer-Menu-Item",
  64. "Homepage",
  65. "Tag",
  66. NULL
  67. };
  68. static const char private_prefix[] = "Private-";
  69. static int known_arbitrary_field(const struct arbitraryfield *field) {
  70. const char **known;
  71. /* Always accept fields starting with a private field prefix. */
  72. if (strncasecmp(field->name, private_prefix, strlen(private_prefix)) == 0)
  73. return 1;
  74. for (known= arbitrary_fields; *known; known++)
  75. if (strcasecmp(field->name, *known) == 0)
  76. return 1;
  77. return 0;
  78. }
  79. /* Do a quick check if vstring is a valid versionnumber. Valid in this case
  80. * means it contains at least one digit. If an error is found increment
  81. * *errs.
  82. */
  83. static void checkversion(const char *vstring, const char *valuename, int *errs) {
  84. const char *p;
  85. if (!vstring || !*vstring) return;
  86. for (p=vstring; *p; p++) if (cisdigit(*p)) return;
  87. fprintf(stderr, _("dpkg-deb - error: %s (`%s') doesn't contain any digits\n"),
  88. valuename, vstring);
  89. (*errs)++;
  90. }
  91. static struct file_info *
  92. file_info_new(const char *filename)
  93. {
  94. struct file_info *fi;
  95. fi = m_malloc(sizeof(*fi));
  96. fi->fn = m_strdup(filename);
  97. fi->next = NULL;
  98. return fi;
  99. }
  100. static struct file_info *
  101. file_info_find_name(struct file_info *list, const char *filename)
  102. {
  103. struct file_info *node;
  104. for (node = list; node; node = node->next)
  105. if (strcmp(node->fn, filename) == 0)
  106. return node;
  107. return NULL;
  108. }
  109. /*
  110. * Read the next filename from a filedescriptor and create a file_info struct
  111. * for it. If there is nothing to read return NULL.
  112. */
  113. static struct file_info *
  114. getfi(const char *root, int fd)
  115. {
  116. static char* fn = NULL;
  117. static size_t fnlen = 0;
  118. size_t i= 0;
  119. struct file_info *fi;
  120. size_t rl = strlen(root);
  121. if (fn == NULL) {
  122. fnlen = rl + MAXFILENAME;
  123. fn = m_malloc(fnlen);
  124. } else if (fnlen < (rl + MAXFILENAME)) {
  125. fnlen = rl + MAXFILENAME;
  126. fn = m_realloc(fn, fnlen);
  127. }
  128. i=sprintf(fn,"%s/",root);
  129. while (1) {
  130. int res;
  131. if (i>=fnlen) {
  132. fnlen += MAXFILENAME;
  133. fn = m_realloc(fn, fnlen);
  134. }
  135. if ((res=read(fd, (fn+i), sizeof(*fn)))<0) {
  136. if ((errno==EINTR) || (errno==EAGAIN))
  137. continue;
  138. else
  139. return NULL;
  140. }
  141. if (res==0) // EOF -> parent died
  142. return NULL;
  143. if (fn[i] == '\0')
  144. break;
  145. i++;
  146. if (i >= MAXFILENAME)
  147. ohshit(_("file name '%.50s...' is too long"), fn + rl + 1);
  148. }
  149. fi = file_info_new(fn + rl + 1);
  150. lstat(fn, &(fi->st));
  151. return fi;
  152. }
  153. /*
  154. * Add a new file_info struct to a single linked list of file_info structs.
  155. * We perform a slight optimization to work around a `feature' in tar: tar
  156. * always recurses into subdirectories if you list a subdirectory. So if an
  157. * entry is added and the previous entry in the list is its subdirectory we
  158. * remove the subdirectory.
  159. *
  160. * After a file_info struct is added to a list it may no longer be freed, we
  161. * assume full responsibility for its memory.
  162. */
  163. static void
  164. add_to_filist(struct file_info **start, struct file_info **end,
  165. struct file_info *fi)
  166. {
  167. if (*start==NULL)
  168. *start=*end=fi;
  169. else
  170. *end=(*end)->next=fi;
  171. }
  172. /*
  173. * Free the memory for all entries in a list of file_info structs.
  174. */
  175. static void
  176. free_filist(struct file_info *fi)
  177. {
  178. while (fi) {
  179. struct file_info *fl;
  180. free(fi->fn);
  181. fl=fi; fi=fi->next;
  182. free(fl);
  183. }
  184. }
  185. /* Overly complex function that builds a .deb file
  186. */
  187. void do_build(const char *const *argv) {
  188. static const char *const maintainerscripts[]= {
  189. PREINSTFILE, POSTINSTFILE, PRERMFILE, POSTRMFILE, NULL
  190. };
  191. char *m;
  192. const char *debar, *directory, *const *mscriptp, *versionstring, *arch;
  193. char *controlfile, *tfbuf;
  194. const char *envbuf;
  195. struct pkginfo *checkedinfo;
  196. struct arbitraryfield *field;
  197. FILE *ar, *cf;
  198. int p1[2],p2[2],p3[2], warns, errs, n, c, subdir, gzfd;
  199. pid_t c1,c2,c3;
  200. struct stat controlstab, datastab, mscriptstab, debarstab;
  201. char conffilename[MAXCONFFILENAME+1];
  202. time_t thetime= 0;
  203. struct file_info *fi;
  204. struct file_info *symlist = NULL;
  205. struct file_info *symlist_end = NULL;
  206. /* Decode our arguments */
  207. directory = *argv++;
  208. if (!directory)
  209. badusage(_("--%s needs a <directory> argument"), cipaction->olong);
  210. /* template for our tempfiles */
  211. if ((envbuf= getenv("TMPDIR")) == NULL)
  212. envbuf= P_tmpdir;
  213. tfbuf = m_malloc(strlen(envbuf) + 13);
  214. strcpy(tfbuf,envbuf);
  215. strcat(tfbuf,"/dpkg.XXXXXX");
  216. subdir= 0;
  217. debar = *argv++;
  218. if (debar != NULL) {
  219. if (*argv) badusage(_("--build takes at most two arguments"));
  220. if (debar) {
  221. if (stat(debar,&debarstab)) {
  222. if (errno != ENOENT)
  223. ohshite(_("unable to check for existence of archive `%.250s'"),debar);
  224. } else if (S_ISDIR(debarstab.st_mode)) {
  225. subdir= 1;
  226. }
  227. }
  228. } else {
  229. m= m_malloc(strlen(directory) + sizeof(DEBEXT));
  230. strcpy(m, directory);
  231. path_rtrim_slash_slashdot(m);
  232. strcat(m, DEBEXT);
  233. debar= m;
  234. }
  235. /* Perform some sanity checks on the to-be-build package.
  236. */
  237. if (nocheckflag) {
  238. if (subdir)
  239. ohshit(_("target is directory - cannot skip control file check"));
  240. warning(_("not checking contents of control area."));
  241. printf(_("dpkg-deb: building an unknown package in '%s'.\n"), debar);
  242. } else {
  243. controlfile= m_malloc(strlen(directory) + sizeof(BUILDCONTROLDIR) +
  244. sizeof(CONTROLFILE) + sizeof(CONFFILESFILE) +
  245. sizeof(POSTINSTFILE) + sizeof(PREINSTFILE) +
  246. sizeof(POSTRMFILE) + sizeof(PRERMFILE) +
  247. MAXCONFFILENAME + 5);
  248. /* Lets start by reading in the control-file so we can check its contents */
  249. strcpy(controlfile, directory);
  250. strcat(controlfile, "/" BUILDCONTROLDIR "/" CONTROLFILE);
  251. warns= 0; errs= 0;
  252. parsedb(controlfile, pdb_recordavailable|pdb_rejectstatus,
  253. &checkedinfo, stderr, &warns);
  254. assert(checkedinfo->available.valid);
  255. if (strspn(checkedinfo->name,
  256. "abcdefghijklmnopqrstuvwxyz0123456789+-.")
  257. != strlen(checkedinfo->name))
  258. ohshit(_("package name has characters that aren't lowercase alphanums or `-+.'"));
  259. if (checkedinfo->priority == pri_other) {
  260. warning(_("'%s' contains user-defined Priority value '%s'"),
  261. controlfile, checkedinfo->otherpriority);
  262. warns++;
  263. }
  264. for (field= checkedinfo->available.arbs; field; field= field->next) {
  265. if (known_arbitrary_field(field))
  266. continue;
  267. warning(_("'%s' contains user-defined field '%s'"),
  268. controlfile, field->name);
  269. warns++;
  270. }
  271. checkversion(checkedinfo->available.version.version,
  272. _("(upstream) version"), &errs);
  273. checkversion(checkedinfo->available.version.revision,
  274. _("Debian revision"), &errs);
  275. if (errs) ohshit(_("%d errors in control file"),errs);
  276. if (subdir) {
  277. versionstring= versiondescribe(&checkedinfo->available.version,vdew_never);
  278. arch= checkedinfo->available.architecture; if (!arch) arch= "";
  279. m= m_malloc(sizeof(DEBEXT)+1+strlen(debar)+1+strlen(checkedinfo->name)+
  280. strlen(versionstring)+1+strlen(arch));
  281. sprintf(m,"%s/%s_%s%s%s" DEBEXT,debar,checkedinfo->name,versionstring,
  282. arch[0] ? "_" : "", arch);
  283. debar= m;
  284. }
  285. printf(_("dpkg-deb: building package `%s' in `%s'.\n"), checkedinfo->name, debar);
  286. /* Check file permissions */
  287. strcpy(controlfile, directory);
  288. strcat(controlfile, "/" BUILDCONTROLDIR "/");
  289. if (lstat(controlfile, &mscriptstab))
  290. ohshite(_("unable to stat control directory"));
  291. if (!S_ISDIR(mscriptstab.st_mode))
  292. ohshit(_("control directory is not a directory"));
  293. if ((mscriptstab.st_mode & 07757) != 0755)
  294. ohshit(_("control directory has bad permissions %03lo (must be >=0755 "
  295. "and <=0775)"), (unsigned long)(mscriptstab.st_mode & 07777));
  296. for (mscriptp= maintainerscripts; *mscriptp; mscriptp++) {
  297. strcpy(controlfile, directory);
  298. strcat(controlfile, "/" BUILDCONTROLDIR "/");
  299. strcat(controlfile, *mscriptp);
  300. if (!lstat(controlfile,&mscriptstab)) {
  301. if (S_ISLNK(mscriptstab.st_mode)) continue;
  302. if (!S_ISREG(mscriptstab.st_mode))
  303. ohshit(_("maintainer script `%.50s' is not a plain file or symlink"),*mscriptp);
  304. if ((mscriptstab.st_mode & 07557) != 0555)
  305. ohshit(_("maintainer script `%.50s' has bad permissions %03lo "
  306. "(must be >=0555 and <=0775)"),
  307. *mscriptp, (unsigned long)(mscriptstab.st_mode & 07777));
  308. } else if (errno != ENOENT) {
  309. ohshite(_("maintainer script `%.50s' is not stattable"),*mscriptp);
  310. }
  311. }
  312. /* Check if conffiles contains sane information */
  313. strcpy(controlfile, directory);
  314. strcat(controlfile, "/" BUILDCONTROLDIR "/" CONFFILESFILE);
  315. if ((cf= fopen(controlfile,"r"))) {
  316. struct file_info *conffiles_head = NULL;
  317. struct file_info *conffiles_tail = NULL;
  318. while (fgets(conffilename,MAXCONFFILENAME+1,cf)) {
  319. n= strlen(conffilename);
  320. if (!n) ohshite(_("empty string from fgets reading conffiles"));
  321. if (conffilename[n-1] != '\n') {
  322. warning(_("conffile name '%.50s...' is too long, or missing final newline"),
  323. conffilename);
  324. warns++;
  325. while ((c= getc(cf)) != EOF && c != '\n');
  326. continue;
  327. }
  328. conffilename[n - 1] = '\0';
  329. strcpy(controlfile, directory);
  330. strcat(controlfile, "/");
  331. strcat(controlfile, conffilename);
  332. if (lstat(controlfile,&controlstab)) {
  333. if (errno == ENOENT) {
  334. if((n > 1) && isspace(conffilename[n-2]))
  335. warning(_("conffile filename '%s' contains trailing white spaces"),
  336. conffilename);
  337. ohshit(_("conffile `%.250s' does not appear in package"), conffilename);
  338. } else
  339. ohshite(_("conffile `%.250s' is not stattable"), conffilename);
  340. } else if (!S_ISREG(controlstab.st_mode)) {
  341. warning(_("conffile '%s' is not a plain file"), conffilename);
  342. warns++;
  343. }
  344. if (file_info_find_name(conffiles_head, conffilename))
  345. warning(_("conffile name '%s' is duplicated"), conffilename);
  346. else {
  347. struct file_info *conffile;
  348. conffile = file_info_new(conffilename);
  349. add_to_filist(&conffiles_head, &conffiles_tail, conffile);
  350. }
  351. }
  352. free_filist(conffiles_head);
  353. if (ferror(cf)) ohshite(_("error reading conffiles file"));
  354. fclose(cf);
  355. } else if (errno != ENOENT) {
  356. ohshite(_("error opening conffiles file"));
  357. }
  358. if (warns)
  359. warning(_("ignoring %d warnings about the control file(s)\n"), warns);
  360. }
  361. m_output(stdout, _("<standard output>"));
  362. /* Now that we have verified everything its time to actually
  363. * build something. Lets start by making the ar-wrapper.
  364. */
  365. if (!(ar=fopen(debar,"wb"))) ohshite(_("unable to create `%.255s'"),debar);
  366. if (setvbuf(ar, NULL, _IONBF, 0))
  367. ohshite(_("unable to unbuffer `%.255s'"), debar);
  368. /* Fork a tar to package the control-section of the package */
  369. unsetenv("TAR_OPTIONS");
  370. m_pipe(p1);
  371. if (!(c1= m_fork())) {
  372. m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
  373. if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory);
  374. if (chdir(BUILDCONTROLDIR)) ohshite(_("failed to chdir to .../DEBIAN"));
  375. execlp(TAR, "tar", "-cf", "-", "--format=gnu", ".", NULL);
  376. ohshite(_("failed to exec tar -cf"));
  377. }
  378. close(p1[1]);
  379. /* Create a temporary file to store the control data in. Immediately unlink
  380. * our temporary file so others can't mess with it.
  381. */
  382. if ((gzfd= mkstemp(tfbuf)) == -1) ohshite(_("failed to make tmpfile (control)"));
  383. /* make sure it's gone, the fd will remain until we close it */
  384. if (unlink(tfbuf)) ohshit(_("failed to unlink tmpfile (control), %s"),
  385. tfbuf);
  386. /* reset this, so we can use it elsewhere */
  387. strcpy(tfbuf,envbuf);
  388. strcat(tfbuf,"/dpkg.XXXXXX");
  389. /* And run gzip to compress our control archive */
  390. if (!(c2= m_fork())) {
  391. m_dup2(p1[0],0); m_dup2(gzfd,1); close(p1[0]); close(gzfd);
  392. compress_cat(compress_type_gzip, 0, 1, "9", _("control"));
  393. }
  394. close(p1[0]);
  395. waitsubproc(c2,"gzip -9c",0);
  396. waitsubproc(c1,"tar -cf",0);
  397. if (fstat(gzfd,&controlstab)) ohshite(_("failed to fstat tmpfile (control)"));
  398. /* We have our first file for the ar-archive. Write a header for it to the
  399. * package and insert it.
  400. */
  401. if (oldformatflag) {
  402. if (fprintf(ar, "%-8s\n%ld\n", OLDARCHIVEVERSION, (long)controlstab.st_size) == EOF)
  403. werr(debar);
  404. } else {
  405. thetime = time(NULL);
  406. if (fprintf(ar,
  407. "!<arch>\n"
  408. "debian-binary %-12lu0 0 100644 %-10ld`\n"
  409. ARCHIVEVERSION "\n"
  410. "%s"
  411. ADMINMEMBER "%-12lu0 0 100644 %-10ld`\n",
  412. thetime,
  413. (long)sizeof(ARCHIVEVERSION),
  414. (sizeof(ARCHIVEVERSION)&1) ? "\n" : "",
  415. (unsigned long)thetime,
  416. (long)controlstab.st_size) == EOF)
  417. werr(debar);
  418. }
  419. if (lseek(gzfd,0,SEEK_SET)) ohshite(_("failed to rewind tmpfile (control)"));
  420. fd_fd_copy(gzfd, fileno(ar), -1, _("control"));
  421. /* Control is done, now we need to archive the data. Start by creating
  422. * a new temporary file. Immediately unlink the temporary file so others
  423. * can't mess with it. */
  424. if (!oldformatflag) {
  425. close(gzfd);
  426. if ((gzfd= mkstemp(tfbuf)) == -1) ohshite(_("failed to make tmpfile (data)"));
  427. /* make sure it's gone, the fd will remain until we close it */
  428. if (unlink(tfbuf)) ohshit(_("failed to unlink tmpfile (data), %s"),
  429. tfbuf);
  430. /* reset these, in case we want to use the later */
  431. strcpy(tfbuf,envbuf);
  432. strcat(tfbuf,"/dpkg.XXXXXX");
  433. }
  434. /* Fork off a tar. We will feed it a list of filenames on stdin later.
  435. */
  436. m_pipe(p1);
  437. m_pipe(p2);
  438. if (!(c1= m_fork())) {
  439. m_dup2(p1[0],0); close(p1[0]); close(p1[1]);
  440. m_dup2(p2[1],1); close(p2[0]); close(p2[1]);
  441. if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory);
  442. execlp(TAR, "tar", "-cf", "-", "--format=gnu", "--null", "-T", "-", "--no-recursion", NULL);
  443. ohshite(_("failed to exec tar -cf"));
  444. }
  445. close(p1[0]);
  446. close(p2[1]);
  447. /* Of course we should not forget to compress the archive as well.. */
  448. if (!(c2= m_fork())) {
  449. close(p1[1]);
  450. m_dup2(p2[0],0); close(p2[0]);
  451. m_dup2(oldformatflag ? fileno(ar) : gzfd,1);
  452. compress_cat(compress_type, 0, 1, compression, _("data"));
  453. }
  454. close(p2[0]);
  455. /* All the pipes are set, now lets run find, and start feeding
  456. * filenames to tar.
  457. */
  458. m_pipe(p3);
  459. if (!(c3= m_fork())) {
  460. m_dup2(p3[1],1); close(p3[0]); close(p3[1]);
  461. if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory);
  462. execlp(FIND, "find", ".", "-path", "./" BUILDCONTROLDIR, "-prune", "-o",
  463. "-print0", NULL);
  464. ohshite(_("failed to exec find"));
  465. }
  466. close(p3[1]);
  467. /* We need to reorder the files so we can make sure that symlinks
  468. * will not appear before their target.
  469. */
  470. while ((fi=getfi(directory, p3[0]))!=NULL)
  471. if (S_ISLNK(fi->st.st_mode))
  472. add_to_filist(&symlist, &symlist_end, fi);
  473. else {
  474. if (write(p1[1], fi->fn, strlen(fi->fn)+1) ==- 1)
  475. ohshite(_("failed to write filename to tar pipe (data)"));
  476. }
  477. close(p3[0]);
  478. waitsubproc(c3,"find",0);
  479. for (fi= symlist;fi;fi= fi->next)
  480. if (write(p1[1], fi->fn, strlen(fi->fn)+1) == -1)
  481. ohshite(_("failed to write filename to tar pipe (data)"));
  482. /* All done, clean up wait for tar and gzip to finish their job */
  483. close(p1[1]);
  484. free_filist(symlist);
  485. waitsubproc(c2, _("<compress> from tar -cf"), 0);
  486. waitsubproc(c1,"tar -cf",0);
  487. /* Okay, we have data.tar.gz as well now, add it to the ar wrapper */
  488. if (!oldformatflag) {
  489. const char *datamember;
  490. switch (compress_type) {
  491. case compress_type_gzip:
  492. datamember = DATAMEMBER_GZ;
  493. break;
  494. case compress_type_bzip2:
  495. datamember = DATAMEMBER_BZ2;
  496. break;
  497. case compress_type_lzma:
  498. datamember = DATAMEMBER_LZMA;
  499. break;
  500. case compress_type_cat:
  501. datamember = DATAMEMBER_CAT;
  502. break;
  503. default:
  504. internerr("unkown compress_type '%i'", compress_type);
  505. }
  506. if (fstat(gzfd, &datastab))
  507. ohshite(_("failed to fstat tmpfile (data)"));
  508. if (fprintf(ar,
  509. "%s"
  510. "%s" "%-12lu0 0 100644 %-10ld`\n",
  511. (controlstab.st_size & 1) ? "\n" : "",
  512. datamember,
  513. (unsigned long)thetime,
  514. (long)datastab.st_size) == EOF)
  515. werr(debar);
  516. if (lseek(gzfd,0,SEEK_SET)) ohshite(_("failed to rewind tmpfile (data)"));
  517. fd_fd_copy(gzfd, fileno(ar), -1, _("cat (data)"));
  518. if (datastab.st_size & 1)
  519. if (putc('\n',ar) == EOF)
  520. werr(debar);
  521. }
  522. if (fclose(ar)) werr(debar);
  523. exit(0);
  524. }