build.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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-2015 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 <string.h>
  30. #include <dirent.h>
  31. #include <fcntl.h>
  32. #include <unistd.h>
  33. #include <stdbool.h>
  34. #include <stdint.h>
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include <dpkg/i18n.h>
  38. #include <dpkg/c-ctype.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. }
  107. fi = file_info_new(fn.buf + root_len);
  108. if (lstat(fn.buf, &(fi->st)) != 0)
  109. ohshite(_("unable to stat file name '%.250s'"), fn.buf);
  110. return fi;
  111. }
  112. /**
  113. * Add a new file_info struct to a single linked list of file_info structs.
  114. *
  115. * We perform a slight optimization to work around a ‘feature’ in tar: tar
  116. * always recurses into subdirectories if you list a subdirectory. So if an
  117. * entry is added and the previous entry in the list is its subdirectory we
  118. * remove the subdirectory.
  119. *
  120. * After a file_info struct is added to a list it may no longer be freed, we
  121. * assume full responsibility for its memory.
  122. */
  123. static void
  124. file_info_list_append(struct file_info **head, struct file_info **tail,
  125. struct file_info *fi)
  126. {
  127. if (*head == NULL)
  128. *head = *tail = fi;
  129. else
  130. *tail = (*tail)->next =fi;
  131. }
  132. /**
  133. * Free the memory for all entries in a list of file_info structs.
  134. */
  135. static void
  136. file_info_list_free(struct file_info *fi)
  137. {
  138. while (fi) {
  139. struct file_info *fl;
  140. fl=fi; fi=fi->next;
  141. file_info_free(fl);
  142. }
  143. }
  144. static void
  145. file_treewalk_feed(const char *dir, int fd_out)
  146. {
  147. int pipefd[2];
  148. pid_t pid;
  149. struct file_info *fi;
  150. struct file_info *symlist = NULL;
  151. struct file_info *symlist_end = NULL;
  152. m_pipe(pipefd);
  153. pid = subproc_fork();
  154. if (pid == 0) {
  155. m_dup2(pipefd[1], 1);
  156. close(pipefd[0]);
  157. close(pipefd[1]);
  158. if (chdir(dir))
  159. ohshite(_("failed to chdir to '%.255s'"), dir);
  160. execlp(FIND, "find", ".", "-path", "./" BUILDCONTROLDIR, "-prune", "-o",
  161. "-print0", NULL);
  162. ohshite(_("unable to execute %s (%s)"), "find", FIND);
  163. }
  164. close(pipefd[1]);
  165. /* We need to reorder the files so we can make sure that symlinks
  166. * will not appear before their target. */
  167. while ((fi = file_info_get(dir, pipefd[0])) != NULL) {
  168. if (strchr(fi->fn, '\n'))
  169. ohshit(_("newline not allowed in pathname '%s'"), fi->fn);
  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_reap(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) && c_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. /**
  286. * Check the control file.
  287. *
  288. * @param dir The directory from where to build the binary package.
  289. * @return The pkginfo struct from the parsed control file.
  290. */
  291. static struct pkginfo *
  292. check_control_file(const char *dir)
  293. {
  294. struct pkginfo *pkg;
  295. char *controlfile;
  296. m_asprintf(&controlfile, "%s/%s/%s", dir, BUILDCONTROLDIR, CONTROLFILE);
  297. parsedb(controlfile, pdb_parse_binary, &pkg);
  298. if (strspn(pkg->set->name, "abcdefghijklmnopqrstuvwxyz0123456789+-.") !=
  299. strlen(pkg->set->name))
  300. ohshit(_("package name has characters that aren't lowercase alphanums or '-+.'"));
  301. if (pkg->priority == PKG_PRIO_OTHER)
  302. warning(_("'%s' contains user-defined Priority value '%s'"),
  303. controlfile, pkg->otherpriority);
  304. free(controlfile);
  305. return pkg;
  306. }
  307. /**
  308. * Perform some sanity checks on the to-be-built package control area.
  309. *
  310. * @param dir The directory from where to build the binary package.
  311. * @return The pkginfo struct from the parsed control file.
  312. */
  313. static struct pkginfo *
  314. check_control_area(const char *dir)
  315. {
  316. struct pkginfo *pkg;
  317. int warns;
  318. /* Start by reading in the control file so we can check its contents. */
  319. pkg = check_control_file(dir);
  320. check_file_perms(dir);
  321. check_conffiles(dir);
  322. warns = warning_get_count();
  323. if (warns)
  324. warning(P_("ignoring %d warning about the control file(s)",
  325. "ignoring %d warnings about the control file(s)", warns),
  326. warns);
  327. return pkg;
  328. }
  329. /**
  330. * Generate the pathname for the destination binary package.
  331. *
  332. * If the pathname cannot be computed, because the destination is a directory,
  333. * then NULL will be returned.
  334. *
  335. * @param dir The directory from where to build the binary package.
  336. * @param dest The destination name, either a file or directory name.
  337. * @return The pathname for the package being built.
  338. */
  339. static char *
  340. gen_dest_pathname(const char *dir, const char *dest)
  341. {
  342. if (dest) {
  343. struct stat dest_stab;
  344. if (stat(dest, &dest_stab)) {
  345. if (errno != ENOENT)
  346. ohshite(_("unable to check for existence of archive '%.250s'"), dest);
  347. } else if (S_ISDIR(dest_stab.st_mode)) {
  348. /* Need to compute the destination name from the package control file. */
  349. return NULL;
  350. }
  351. return m_strdup(dest);
  352. } else {
  353. char *pathname;
  354. pathname = m_malloc(strlen(dir) + sizeof(DEBEXT));
  355. strcpy(pathname, dir);
  356. path_trim_slash_slashdot(pathname);
  357. strcat(pathname, DEBEXT);
  358. return pathname;
  359. }
  360. }
  361. /**
  362. * Generate the pathname for the destination binary package from control file.
  363. *
  364. * @return The pathname for the package being built.
  365. */
  366. static char *
  367. gen_dest_pathname_from_pkg(const char *dir, struct pkginfo *pkg)
  368. {
  369. const char *arch_sep;
  370. char *path;
  371. if (pkg->available.arch->type == DPKG_ARCH_NONE ||
  372. pkg->available.arch->type == DPKG_ARCH_EMPTY)
  373. arch_sep = "";
  374. else
  375. arch_sep = "_";
  376. m_asprintf(&path, "%s/%s_%s%s%s%s", dir, pkg->set->name,
  377. versiondescribe(&pkg->available.version, vdew_never),
  378. arch_sep, pkg->available.arch->name, DEBEXT);
  379. return path;
  380. }
  381. /**
  382. * Overly complex function that builds a .deb file.
  383. */
  384. int
  385. do_build(const char *const *argv)
  386. {
  387. struct compress_params control_compress_params;
  388. struct dpkg_error err;
  389. const char *dir, *dest;
  390. char *debar;
  391. char *tfbuf;
  392. int arfd;
  393. int p1[2], p2[2], gzfd;
  394. pid_t c1, c2;
  395. /* Decode our arguments. */
  396. dir = *argv++;
  397. if (!dir)
  398. badusage(_("--%s needs a <directory> argument"), cipaction->olong);
  399. dest = *argv++;
  400. if (dest && *argv)
  401. badusage(_("--%s takes at most two arguments"), cipaction->olong);
  402. debar = gen_dest_pathname(dir, dest);
  403. /* Perform some sanity checks on the to-be-build package. */
  404. if (nocheckflag) {
  405. if (debar == NULL)
  406. ohshit(_("target is directory - cannot skip control file check"));
  407. warning(_("not checking contents of control area"));
  408. printf(_("dpkg-deb: building an unknown package in '%s'.\n"), debar);
  409. } else {
  410. struct pkginfo *pkg;
  411. pkg = check_control_area(dir);
  412. if (debar == NULL)
  413. debar = gen_dest_pathname_from_pkg(dest, pkg);
  414. printf(_("dpkg-deb: building package '%s' in '%s'.\n"),
  415. pkg->set->name, debar);
  416. }
  417. m_output(stdout, _("<standard output>"));
  418. /* Now that we have verified everything its time to actually
  419. * build something. Let's start by making the ar-wrapper. */
  420. arfd = creat(debar, 0644);
  421. if (arfd < 0)
  422. ohshite(_("unable to create '%.255s'"), debar);
  423. /* Fork a tar to package the control-section of the package. */
  424. unsetenv("TAR_OPTIONS");
  425. m_pipe(p1);
  426. c1 = subproc_fork();
  427. if (!c1) {
  428. m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
  429. if (chdir(dir))
  430. ohshite(_("failed to chdir to '%.255s'"), dir);
  431. if (chdir(BUILDCONTROLDIR))
  432. ohshite(_("failed to chdir to '%.255s'"), ".../DEBIAN");
  433. execlp(TAR, "tar", "-cf", "-", "--format=gnu", ".", NULL);
  434. ohshite(_("unable to execute %s (%s)"), "tar -cf", TAR);
  435. }
  436. close(p1[1]);
  437. /* Create a temporary file to store the control data in. Immediately
  438. * unlink our temporary file so others can't mess with it. */
  439. tfbuf = path_make_temp_template("dpkg-deb");
  440. gzfd = mkstemp(tfbuf);
  441. if (gzfd == -1)
  442. ohshite(_("failed to make temporary file (%s)"), _("control member"));
  443. /* Make sure it's gone, the fd will remain until we close it. */
  444. if (unlink(tfbuf))
  445. ohshit(_("failed to unlink temporary file (%s), %s"), _("control member"),
  446. tfbuf);
  447. free(tfbuf);
  448. /* And run the compressor on our control archive. */
  449. if (opt_uniform_compression) {
  450. control_compress_params = compress_params;
  451. } else {
  452. control_compress_params.type = COMPRESSOR_TYPE_GZIP;
  453. control_compress_params.strategy = COMPRESSOR_STRATEGY_NONE;
  454. control_compress_params.level = -1;
  455. if (!compressor_check_params(&control_compress_params, &err))
  456. internerr("invalid control member compressor params: %s", err.str);
  457. }
  458. c2 = subproc_fork();
  459. if (!c2) {
  460. compress_filter(&control_compress_params, p1[0], gzfd, _("compressing control member"));
  461. exit(0);
  462. }
  463. close(p1[0]);
  464. subproc_reap(c2, _("<compress> from tar -cf"), 0);
  465. subproc_reap(c1, "tar -cf", 0);
  466. if (lseek(gzfd, 0, SEEK_SET))
  467. ohshite(_("failed to rewind temporary file (%s)"), _("control member"));
  468. /* We have our first file for the ar-archive. Write a header for it
  469. * to the package and insert it. */
  470. if (deb_format.major == 0) {
  471. struct stat controlstab;
  472. char versionbuf[40];
  473. if (fstat(gzfd, &controlstab))
  474. ohshite(_("failed to stat temporary file (%s)"), _("control member"));
  475. sprintf(versionbuf, "%-8s\n%jd\n", OLDARCHIVEVERSION,
  476. (intmax_t)controlstab.st_size);
  477. if (fd_write(arfd, versionbuf, strlen(versionbuf)) < 0)
  478. ohshite(_("error writing '%s'"), debar);
  479. if (fd_fd_copy(gzfd, arfd, -1, &err) < 0)
  480. ohshit(_("cannot copy '%s' into archive '%s': %s"), _("control member"),
  481. debar, err.str);
  482. } else if (deb_format.major == 2) {
  483. const char deb_magic[] = ARCHIVEVERSION "\n";
  484. char adminmember[16 + 1];
  485. sprintf(adminmember, "%s%s", ADMINMEMBER,
  486. compressor_get_extension(control_compress_params.type));
  487. dpkg_ar_put_magic(debar, arfd);
  488. dpkg_ar_member_put_mem(debar, arfd, DEBMAGIC, deb_magic, strlen(deb_magic));
  489. dpkg_ar_member_put_file(debar, arfd, adminmember, gzfd, -1);
  490. } else {
  491. internerr("unknown deb format version %d.%d", deb_format.major, deb_format.minor);
  492. }
  493. close(gzfd);
  494. /* Control is done, now we need to archive the data. */
  495. if (deb_format.major == 0) {
  496. /* In old format, the data member is just concatenated after the
  497. * control member, so we do not need a temporary file and can use
  498. * the compression file descriptor. */
  499. gzfd = arfd;
  500. } else if (deb_format.major == 2) {
  501. /* Start by creating a new temporary file. Immediately unlink the
  502. * temporary file so others can't mess with it. */
  503. tfbuf = path_make_temp_template("dpkg-deb");
  504. gzfd = mkstemp(tfbuf);
  505. if (gzfd == -1)
  506. ohshite(_("failed to make temporary file (%s)"), _("data member"));
  507. /* Make sure it's gone, the fd will remain until we close it. */
  508. if (unlink(tfbuf))
  509. ohshit(_("failed to unlink temporary file (%s), %s"), _("data member"),
  510. tfbuf);
  511. free(tfbuf);
  512. } else {
  513. internerr("unknown deb format version %d.%d", deb_format.major, deb_format.minor);
  514. }
  515. /* Fork off a tar. We will feed it a list of filenames on stdin later. */
  516. m_pipe(p1);
  517. m_pipe(p2);
  518. c1 = subproc_fork();
  519. if (!c1) {
  520. m_dup2(p1[0],0); close(p1[0]); close(p1[1]);
  521. m_dup2(p2[1],1); close(p2[0]); close(p2[1]);
  522. if (chdir(dir))
  523. ohshite(_("failed to chdir to '%.255s'"), dir);
  524. execlp(TAR, "tar", "-cf", "-", "--format=gnu", "--null", "--no-unquote",
  525. "--no-recursion", "-T", "-", NULL);
  526. ohshite(_("unable to execute %s (%s)"), "tar -cf", TAR);
  527. }
  528. close(p1[0]);
  529. close(p2[1]);
  530. /* Of course we should not forget to compress the archive as well. */
  531. c2 = subproc_fork();
  532. if (!c2) {
  533. close(p1[1]);
  534. compress_filter(&compress_params, p2[0], gzfd, _("compressing data member"));
  535. exit(0);
  536. }
  537. close(p2[0]);
  538. /* All the pipes are set, now lets walk the tree, and start feeding
  539. * filenames to tar. */
  540. file_treewalk_feed(dir, p1[1]);
  541. /* All done, clean up wait for tar and <compress> to finish their job. */
  542. close(p1[1]);
  543. subproc_reap(c2, _("<compress> from tar -cf"), 0);
  544. subproc_reap(c1, "tar -cf", 0);
  545. /* Okay, we have data.tar as well now, add it to the ar wrapper. */
  546. if (deb_format.major == 2) {
  547. char datamember[16 + 1];
  548. sprintf(datamember, "%s%s", DATAMEMBER,
  549. compressor_get_extension(compress_params.type));
  550. if (lseek(gzfd, 0, SEEK_SET))
  551. ohshite(_("failed to rewind temporary file (%s)"), _("data member"));
  552. dpkg_ar_member_put_file(debar, arfd, datamember, gzfd, -1);
  553. close(gzfd);
  554. }
  555. if (fsync(arfd))
  556. ohshite(_("unable to sync file '%s'"), debar);
  557. if (close(arfd))
  558. ohshite(_("unable to close file '%s'"), debar);
  559. free(debar);
  560. return 0;
  561. }