build.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. * Copyright © 2007-2014 Guillem Jover <guillem@debian.org>
  8. *
  9. * This is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. #include <config.h>
  23. #include <compat.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <sys/wait.h>
  27. #include <errno.h>
  28. #include <limits.h>
  29. #include <ctype.h>
  30. #include <string.h>
  31. #include <dirent.h>
  32. #include <fcntl.h>
  33. #include <unistd.h>
  34. #include <stdbool.h>
  35. #include <stdint.h>
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <dpkg/i18n.h>
  39. #include <dpkg/dpkg.h>
  40. #include <dpkg/dpkg-db.h>
  41. #include <dpkg/path.h>
  42. #include <dpkg/varbuf.h>
  43. #include <dpkg/fdio.h>
  44. #include <dpkg/buffer.h>
  45. #include <dpkg/subproc.h>
  46. #include <dpkg/compress.h>
  47. #include <dpkg/ar.h>
  48. #include <dpkg/options.h>
  49. #include "dpkg-deb.h"
  50. /**
  51. * Simple structure to store information about a file.
  52. */
  53. struct file_info {
  54. struct file_info *next;
  55. struct stat st;
  56. char *fn;
  57. };
  58. static struct file_info *
  59. file_info_new(const char *filename)
  60. {
  61. struct file_info *fi;
  62. fi = m_malloc(sizeof(*fi));
  63. fi->fn = m_strdup(filename);
  64. fi->next = NULL;
  65. return fi;
  66. }
  67. static void
  68. file_info_free(struct file_info *fi)
  69. {
  70. free(fi->fn);
  71. free(fi);
  72. }
  73. static struct file_info *
  74. file_info_find_name(struct file_info *list, const char *filename)
  75. {
  76. struct file_info *node;
  77. for (node = list; node; node = node->next)
  78. if (strcmp(node->fn, filename) == 0)
  79. return node;
  80. return NULL;
  81. }
  82. /**
  83. * Read a filename from the file descriptor and create a file_info struct.
  84. *
  85. * @return A file_info struct or NULL if there is nothing to read.
  86. */
  87. static struct file_info *
  88. file_info_get(const char *root, int fd)
  89. {
  90. static struct varbuf fn = VARBUF_INIT;
  91. struct file_info *fi;
  92. size_t root_len;
  93. varbuf_reset(&fn);
  94. root_len = varbuf_printf(&fn, "%s/", root);
  95. while (1) {
  96. int res;
  97. varbuf_grow(&fn, 1);
  98. res = fd_read(fd, (fn.buf + fn.used), 1);
  99. if (res < 0)
  100. return NULL;
  101. if (res == 0) /* EOF -> parent died. */
  102. return NULL;
  103. if (fn.buf[fn.used] == '\0')
  104. break;
  105. varbuf_trunc(&fn, fn.used + 1);
  106. if (fn.used >= MAXFILENAME)
  107. ohshit(_("file name '%.50s...' is too long"), fn.buf + root_len);
  108. }
  109. fi = file_info_new(fn.buf + root_len);
  110. if (lstat(fn.buf, &(fi->st)) != 0)
  111. ohshite(_("unable to stat file name '%.250s'"), fn.buf);
  112. return fi;
  113. }
  114. /**
  115. * Add a new file_info struct to a single linked list of file_info structs.
  116. *
  117. * We perform a slight optimization to work around a ‘feature’ in tar: tar
  118. * always recurses into subdirectories if you list a subdirectory. So if an
  119. * entry is added and the previous entry in the list is its subdirectory we
  120. * remove the subdirectory.
  121. *
  122. * After a file_info struct is added to a list it may no longer be freed, we
  123. * assume full responsibility for its memory.
  124. */
  125. static void
  126. file_info_list_append(struct file_info **head, struct file_info **tail,
  127. struct file_info *fi)
  128. {
  129. if (*head == NULL)
  130. *head = *tail = fi;
  131. else
  132. *tail = (*tail)->next =fi;
  133. }
  134. /**
  135. * Free the memory for all entries in a list of file_info structs.
  136. */
  137. static void
  138. file_info_list_free(struct file_info *fi)
  139. {
  140. while (fi) {
  141. struct file_info *fl;
  142. fl=fi; fi=fi->next;
  143. file_info_free(fl);
  144. }
  145. }
  146. static void
  147. file_treewalk_feed(const char *dir, int fd_out)
  148. {
  149. int pipefd[2];
  150. pid_t pid;
  151. struct file_info *fi;
  152. struct file_info *symlist = NULL;
  153. struct file_info *symlist_end = NULL;
  154. m_pipe(pipefd);
  155. pid = subproc_fork();
  156. if (pid == 0) {
  157. m_dup2(pipefd[1], 1);
  158. close(pipefd[0]);
  159. close(pipefd[1]);
  160. if (chdir(dir))
  161. ohshite(_("failed to chdir to `%.255s'"), dir);
  162. execlp(FIND, "find", ".", "-path", "./" BUILDCONTROLDIR, "-prune", "-o",
  163. "-print0", NULL);
  164. ohshite(_("unable to execute %s (%s)"), "find", FIND);
  165. }
  166. close(pipefd[1]);
  167. /* We need to reorder the files so we can make sure that symlinks
  168. * will not appear before their target. */
  169. while ((fi = file_info_get(dir, pipefd[0])) != NULL) {
  170. if (S_ISLNK(fi->st.st_mode)) {
  171. file_info_list_append(&symlist, &symlist_end, fi);
  172. } else {
  173. if (fd_write(fd_out, fi->fn, strlen(fi->fn) + 1) < 0)
  174. ohshite(_("failed to write filename to tar pipe (%s)"),
  175. _("data member"));
  176. file_info_free(fi);
  177. }
  178. }
  179. close(pipefd[0]);
  180. subproc_wait_check(pid, "find", 0);
  181. for (fi = symlist; fi; fi = fi->next)
  182. if (fd_write(fd_out, fi->fn, strlen(fi->fn) + 1) < 0)
  183. ohshite(_("failed to write filename to tar pipe (%s)"), _("data member"));
  184. file_info_list_free(symlist);
  185. }
  186. static const char *const maintainerscripts[] = {
  187. PREINSTFILE,
  188. POSTINSTFILE,
  189. PRERMFILE,
  190. POSTRMFILE,
  191. NULL,
  192. };
  193. /**
  194. * Check control directory and file permissions.
  195. */
  196. static void
  197. check_file_perms(const char *dir)
  198. {
  199. struct varbuf path = VARBUF_INIT;
  200. const char *const *mscriptp;
  201. struct stat mscriptstab;
  202. varbuf_printf(&path, "%s/%s/", dir, BUILDCONTROLDIR);
  203. if (lstat(path.buf, &mscriptstab))
  204. ohshite(_("unable to stat control directory"));
  205. if (!S_ISDIR(mscriptstab.st_mode))
  206. ohshit(_("control directory is not a directory"));
  207. if ((mscriptstab.st_mode & 07757) != 0755)
  208. ohshit(_("control directory has bad permissions %03lo "
  209. "(must be >=0755 and <=0775)"),
  210. (unsigned long)(mscriptstab.st_mode & 07777));
  211. for (mscriptp = maintainerscripts; *mscriptp; mscriptp++) {
  212. varbuf_reset(&path);
  213. varbuf_printf(&path, "%s/%s/%s", dir, BUILDCONTROLDIR, *mscriptp);
  214. if (!lstat(path.buf, &mscriptstab)) {
  215. if (S_ISLNK(mscriptstab.st_mode))
  216. continue;
  217. if (!S_ISREG(mscriptstab.st_mode))
  218. ohshit(_("maintainer script `%.50s' is not a plain file or symlink"),
  219. *mscriptp);
  220. if ((mscriptstab.st_mode & 07557) != 0555)
  221. ohshit(_("maintainer script `%.50s' has bad permissions %03lo "
  222. "(must be >=0555 and <=0775)"),
  223. *mscriptp, (unsigned long)(mscriptstab.st_mode & 07777));
  224. } else if (errno != ENOENT) {
  225. ohshite(_("maintainer script `%.50s' is not stattable"), *mscriptp);
  226. }
  227. }
  228. varbuf_destroy(&path);
  229. }
  230. /**
  231. * Check if conffiles contains sane information.
  232. */
  233. static void
  234. check_conffiles(const char *dir)
  235. {
  236. FILE *cf;
  237. struct varbuf controlfile = VARBUF_INIT;
  238. char conffilename[MAXCONFFILENAME + 1];
  239. struct file_info *conffiles_head = NULL;
  240. struct file_info *conffiles_tail = NULL;
  241. varbuf_printf(&controlfile, "%s/%s/%s", dir, BUILDCONTROLDIR, CONFFILESFILE);
  242. cf = fopen(controlfile.buf, "r");
  243. if (cf == NULL) {
  244. if (errno == ENOENT)
  245. return;
  246. ohshite(_("error opening conffiles file"));
  247. }
  248. while (fgets(conffilename, MAXCONFFILENAME + 1, cf)) {
  249. struct stat controlstab;
  250. int n;
  251. n = strlen(conffilename);
  252. if (!n)
  253. ohshite(_("empty string from fgets reading conffiles"));
  254. if (conffilename[n - 1] != '\n')
  255. ohshit(_("conffile name '%s' is too long, or missing final newline"),
  256. conffilename);
  257. conffilename[n - 1] = '\0';
  258. varbuf_reset(&controlfile);
  259. varbuf_printf(&controlfile, "%s/%s", dir, conffilename);
  260. if (lstat(controlfile.buf, &controlstab)) {
  261. if (errno == ENOENT) {
  262. if ((n > 1) && isspace(conffilename[n - 2]))
  263. warning(_("conffile filename '%s' contains trailing white spaces"),
  264. conffilename);
  265. ohshit(_("conffile `%.250s' does not appear in package"), conffilename);
  266. } else
  267. ohshite(_("conffile `%.250s' is not stattable"), conffilename);
  268. } else if (!S_ISREG(controlstab.st_mode)) {
  269. warning(_("conffile '%s' is not a plain file"), conffilename);
  270. }
  271. if (file_info_find_name(conffiles_head, conffilename)) {
  272. warning(_("conffile name '%s' is duplicated"), conffilename);
  273. } else {
  274. struct file_info *conffile;
  275. conffile = file_info_new(conffilename);
  276. file_info_list_append(&conffiles_head, &conffiles_tail, conffile);
  277. }
  278. }
  279. file_info_list_free(conffiles_head);
  280. varbuf_destroy(&controlfile);
  281. if (ferror(cf))
  282. ohshite(_("error reading conffiles file"));
  283. fclose(cf);
  284. }
  285. static const char *arbitrary_fields[] = {
  286. "Built-For-Profiles",
  287. "Built-Using",
  288. "Package-Type",
  289. "Subarchitecture",
  290. "Kernel-Version",
  291. "Installer-Menu-Item",
  292. "Homepage",
  293. "Tag",
  294. NULL
  295. };
  296. static const char private_prefix[] = "Private-";
  297. static bool
  298. known_arbitrary_field(const struct arbitraryfield *field)
  299. {
  300. const char **known;
  301. /* Always accept fields starting with a private field prefix. */
  302. if (strncasecmp(field->name, private_prefix, strlen(private_prefix)) == 0)
  303. return true;
  304. for (known = arbitrary_fields; *known; known++)
  305. if (strcasecmp(field->name, *known) == 0)
  306. return true;
  307. return false;
  308. }
  309. /**
  310. * Perform some sanity checks on the to-be-built package.
  311. *
  312. * @return The pkginfo struct from the parsed control file.
  313. */
  314. static struct pkginfo *
  315. check_new_pkg(const char *dir)
  316. {
  317. struct pkginfo *pkg;
  318. struct arbitraryfield *field;
  319. char *controlfile;
  320. int warns;
  321. /* Start by reading in the control file so we can check its contents. */
  322. m_asprintf(&controlfile, "%s/%s/%s", dir, BUILDCONTROLDIR, CONTROLFILE);
  323. parsedb(controlfile, pdb_parse_binary, &pkg);
  324. if (strspn(pkg->set->name, "abcdefghijklmnopqrstuvwxyz0123456789+-.") !=
  325. strlen(pkg->set->name))
  326. ohshit(_("package name has characters that aren't lowercase alphanums or `-+.'"));
  327. if (pkg->priority == PKG_PRIO_OTHER)
  328. warning(_("'%s' contains user-defined Priority value '%s'"),
  329. controlfile, pkg->otherpriority);
  330. for (field = pkg->available.arbs; field; field = field->next) {
  331. if (known_arbitrary_field(field))
  332. continue;
  333. warning(_("'%s' contains user-defined field '%s'"), controlfile,
  334. field->name);
  335. }
  336. free(controlfile);
  337. check_file_perms(dir);
  338. check_conffiles(dir);
  339. warns = warning_get_count();
  340. if (warns)
  341. warning(P_("ignoring %d warning about the control file(s)",
  342. "ignoring %d warnings about the control file(s)", warns),
  343. warns);
  344. return pkg;
  345. }
  346. /**
  347. * Generate the pathname for the to-be-built package.
  348. *
  349. * @return The pathname for the package being built.
  350. */
  351. static char *
  352. pkg_get_pathname(const char *dir, struct pkginfo *pkg)
  353. {
  354. char *path;
  355. const char *versionstring, *arch_sep;
  356. versionstring = versiondescribe(&pkg->available.version, vdew_never);
  357. arch_sep = pkg->available.arch->type == DPKG_ARCH_NONE ? "" : "_";
  358. m_asprintf(&path, "%s/%s_%s%s%s%s", dir, pkg->set->name, versionstring,
  359. arch_sep, pkg->available.arch->name, DEBEXT);
  360. return path;
  361. }
  362. /**
  363. * Overly complex function that builds a .deb file.
  364. */
  365. int
  366. do_build(const char *const *argv)
  367. {
  368. struct compress_params control_compress_params;
  369. struct dpkg_error err;
  370. const char *debar, *dir;
  371. bool subdir;
  372. char *tfbuf;
  373. int arfd;
  374. int p1[2], p2[2], gzfd;
  375. pid_t c1, c2;
  376. /* Decode our arguments. */
  377. dir = *argv++;
  378. if (!dir)
  379. badusage(_("--%s needs a <directory> argument"), cipaction->olong);
  380. subdir = false;
  381. debar = *argv++;
  382. if (debar != NULL) {
  383. struct stat debarstab;
  384. if (*argv)
  385. badusage(_("--%s takes at most two arguments"), cipaction->olong);
  386. if (stat(debar, &debarstab)) {
  387. if (errno != ENOENT)
  388. ohshite(_("unable to check for existence of archive `%.250s'"), debar);
  389. } else if (S_ISDIR(debarstab.st_mode)) {
  390. subdir = true;
  391. }
  392. } else {
  393. char *m;
  394. m= m_malloc(strlen(dir) + sizeof(DEBEXT));
  395. strcpy(m, dir);
  396. path_trim_slash_slashdot(m);
  397. strcat(m, DEBEXT);
  398. debar= m;
  399. }
  400. /* Perform some sanity checks on the to-be-build package. */
  401. if (nocheckflag) {
  402. if (subdir)
  403. ohshit(_("target is directory - cannot skip control file check"));
  404. warning(_("not checking contents of control area"));
  405. printf(_("dpkg-deb: building an unknown package in '%s'.\n"), debar);
  406. } else {
  407. struct pkginfo *pkg;
  408. pkg = check_new_pkg(dir);
  409. if (subdir)
  410. debar = pkg_get_pathname(debar, pkg);
  411. printf(_("dpkg-deb: building package `%s' in `%s'.\n"),
  412. pkg->set->name, debar);
  413. }
  414. m_output(stdout, _("<standard output>"));
  415. /* Now that we have verified everything its time to actually
  416. * build something. Let's start by making the ar-wrapper. */
  417. arfd = creat(debar, 0644);
  418. if (arfd < 0)
  419. ohshite(_("unable to create `%.255s'"), debar);
  420. /* Fork a tar to package the control-section of the package. */
  421. unsetenv("TAR_OPTIONS");
  422. m_pipe(p1);
  423. c1 = subproc_fork();
  424. if (!c1) {
  425. m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
  426. if (chdir(dir))
  427. ohshite(_("failed to chdir to `%.255s'"), dir);
  428. if (chdir(BUILDCONTROLDIR))
  429. ohshite(_("failed to chdir to `%.255s'"), ".../DEBIAN");
  430. execlp(TAR, "tar", "-cf", "-", "--format=gnu", ".", NULL);
  431. ohshite(_("unable to execute %s (%s)"), "tar -cf", TAR);
  432. }
  433. close(p1[1]);
  434. /* Create a temporary file to store the control data in. Immediately
  435. * unlink our temporary file so others can't mess with it. */
  436. tfbuf = path_make_temp_template("dpkg-deb");
  437. gzfd = mkstemp(tfbuf);
  438. if (gzfd == -1)
  439. ohshite(_("failed to make temporary file (%s)"), _("control member"));
  440. /* Make sure it's gone, the fd will remain until we close it. */
  441. if (unlink(tfbuf))
  442. ohshit(_("failed to unlink temporary file (%s), %s"), _("control member"),
  443. tfbuf);
  444. free(tfbuf);
  445. /* And run the compressor on our control archive. */
  446. if (opt_uniform_compression) {
  447. control_compress_params = compress_params;
  448. } else {
  449. control_compress_params.type = COMPRESSOR_TYPE_GZIP;
  450. control_compress_params.strategy = COMPRESSOR_STRATEGY_NONE;
  451. control_compress_params.level = -1;
  452. }
  453. c2 = subproc_fork();
  454. if (!c2) {
  455. compress_filter(&control_compress_params, p1[0], gzfd, _("compressing control member"));
  456. exit(0);
  457. }
  458. close(p1[0]);
  459. subproc_wait_check(c2, "gzip -9c", 0);
  460. subproc_wait_check(c1, "tar -cf", 0);
  461. if (lseek(gzfd, 0, SEEK_SET))
  462. ohshite(_("failed to rewind temporary file (%s)"), _("control member"));
  463. /* We have our first file for the ar-archive. Write a header for it
  464. * to the package and insert it. */
  465. if (deb_format.major == 0) {
  466. struct stat controlstab;
  467. char versionbuf[40];
  468. if (fstat(gzfd, &controlstab))
  469. ohshite(_("failed to stat temporary file (%s)"), _("control member"));
  470. sprintf(versionbuf, "%-8s\n%jd\n", OLDARCHIVEVERSION,
  471. (intmax_t)controlstab.st_size);
  472. if (fd_write(arfd, versionbuf, strlen(versionbuf)) < 0)
  473. ohshite(_("error writing `%s'"), debar);
  474. if (fd_fd_copy(gzfd, arfd, -1, &err) < 0)
  475. ohshit(_("cannot copy '%s' into archive '%s': %s"), _("control member"),
  476. debar, err.str);
  477. } else if (deb_format.major == 2) {
  478. const char deb_magic[] = ARCHIVEVERSION "\n";
  479. char adminmember[16 + 1];
  480. sprintf(adminmember, "%s%s", ADMINMEMBER,
  481. compressor_get_extension(control_compress_params.type));
  482. dpkg_ar_put_magic(debar, arfd);
  483. dpkg_ar_member_put_mem(debar, arfd, DEBMAGIC, deb_magic, strlen(deb_magic));
  484. dpkg_ar_member_put_file(debar, arfd, adminmember, gzfd, -1);
  485. } else {
  486. internerr("unknown deb format version %d.%d", deb_format.major, deb_format.minor);
  487. }
  488. close(gzfd);
  489. /* Control is done, now we need to archive the data. */
  490. if (deb_format.major == 0) {
  491. /* In old format, the data member is just concatenated after the
  492. * control member, so we do not need a temporary file and can use
  493. * the compression file descriptor. */
  494. gzfd = arfd;
  495. } else if (deb_format.major == 2) {
  496. /* Start by creating a new temporary file. Immediately unlink the
  497. * temporary file so others can't mess with it. */
  498. tfbuf = path_make_temp_template("dpkg-deb");
  499. gzfd = mkstemp(tfbuf);
  500. if (gzfd == -1)
  501. ohshite(_("failed to make temporary file (%s)"), _("data member"));
  502. /* Make sure it's gone, the fd will remain until we close it. */
  503. if (unlink(tfbuf))
  504. ohshit(_("failed to unlink temporary file (%s), %s"), _("data member"),
  505. tfbuf);
  506. free(tfbuf);
  507. } else {
  508. internerr("unknown deb format version %d.%d", deb_format.major, deb_format.minor);
  509. }
  510. /* Fork off a tar. We will feed it a list of filenames on stdin later. */
  511. m_pipe(p1);
  512. m_pipe(p2);
  513. c1 = subproc_fork();
  514. if (!c1) {
  515. m_dup2(p1[0],0); close(p1[0]); close(p1[1]);
  516. m_dup2(p2[1],1); close(p2[0]); close(p2[1]);
  517. if (chdir(dir))
  518. ohshite(_("failed to chdir to `%.255s'"), dir);
  519. execlp(TAR, "tar", "-cf", "-", "--format=gnu", "--null", "--no-unquote",
  520. "-T", "-", "--no-recursion", NULL);
  521. ohshite(_("unable to execute %s (%s)"), "tar -cf", TAR);
  522. }
  523. close(p1[0]);
  524. close(p2[1]);
  525. /* Of course we should not forget to compress the archive as well. */
  526. c2 = subproc_fork();
  527. if (!c2) {
  528. close(p1[1]);
  529. compress_filter(&compress_params, p2[0], gzfd, _("compressing data member"));
  530. exit(0);
  531. }
  532. close(p2[0]);
  533. /* All the pipes are set, now lets walk the tree, and start feeding
  534. * filenames to tar. */
  535. file_treewalk_feed(dir, p1[1]);
  536. /* All done, clean up wait for tar and gzip to finish their job. */
  537. close(p1[1]);
  538. subproc_wait_check(c2, _("<compress> from tar -cf"), 0);
  539. subproc_wait_check(c1, "tar -cf", 0);
  540. /* Okay, we have data.tar as well now, add it to the ar wrapper. */
  541. if (deb_format.major == 2) {
  542. char datamember[16 + 1];
  543. sprintf(datamember, "%s%s", DATAMEMBER,
  544. compressor_get_extension(compress_params.type));
  545. if (lseek(gzfd, 0, SEEK_SET))
  546. ohshite(_("failed to rewind temporary file (%s)"), _("data member"));
  547. dpkg_ar_member_put_file(debar, arfd, datamember, gzfd, -1);
  548. close(gzfd);
  549. }
  550. if (fsync(arfd))
  551. ohshite(_("unable to sync file '%s'"), debar);
  552. if (close(arfd))
  553. ohshite(_("unable to close file '%s'"), debar);
  554. return 0;
  555. }