build.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * dpkg-deb - construction and deconstruction of *.deb archives
  3. * build.c - building archives
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ijackson@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 <time.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/c-ctype.h>
  40. #include <dpkg/dpkg.h>
  41. #include <dpkg/dpkg-db.h>
  42. #include <dpkg/path.h>
  43. #include <dpkg/treewalk.h>
  44. #include <dpkg/varbuf.h>
  45. #include <dpkg/fdio.h>
  46. #include <dpkg/buffer.h>
  47. #include <dpkg/subproc.h>
  48. #include <dpkg/compress.h>
  49. #include <dpkg/ar.h>
  50. #include <dpkg/options.h>
  51. #include "dpkg-deb.h"
  52. static void
  53. control_treewalk_feed(const char *dir, int fd_out)
  54. {
  55. struct treeroot *tree;
  56. struct treenode *node;
  57. tree = treewalk_open(dir, TREEWALK_NONE, NULL);
  58. for (node = treewalk_node(tree); node; node = treewalk_next(tree)) {
  59. char *nodename;
  60. nodename = str_fmt("./%s", treenode_get_virtname(node));
  61. if (fd_write(fd_out, nodename, strlen(nodename) + 1) < 0)
  62. ohshite(_("failed to write filename to tar pipe (%s)"),
  63. _("control member"));
  64. free(nodename);
  65. }
  66. treewalk_close(tree);
  67. }
  68. /**
  69. * Simple structure to store information about a file.
  70. */
  71. struct file_info {
  72. struct file_info *next;
  73. char *fn;
  74. };
  75. static struct file_info *
  76. file_info_new(const char *filename)
  77. {
  78. struct file_info *fi;
  79. fi = m_malloc(sizeof(*fi));
  80. fi->fn = m_strdup(filename);
  81. fi->next = NULL;
  82. return fi;
  83. }
  84. static void
  85. file_info_free(struct file_info *fi)
  86. {
  87. free(fi->fn);
  88. free(fi);
  89. }
  90. static struct file_info *
  91. file_info_find_name(struct file_info *list, const char *filename)
  92. {
  93. struct file_info *node;
  94. for (node = list; node; node = node->next)
  95. if (strcmp(node->fn, filename) == 0)
  96. return node;
  97. return NULL;
  98. }
  99. /**
  100. * Add a new file_info struct to a single linked list of file_info structs.
  101. *
  102. * We perform a slight optimization to work around a ‘feature’ in tar: tar
  103. * always recurses into subdirectories if you list a subdirectory. So if an
  104. * entry is added and the previous entry in the list is its subdirectory we
  105. * remove the subdirectory.
  106. *
  107. * After a file_info struct is added to a list it may no longer be freed, we
  108. * assume full responsibility for its memory.
  109. */
  110. static void
  111. file_info_list_append(struct file_info **head, struct file_info **tail,
  112. struct file_info *fi)
  113. {
  114. if (*head == NULL)
  115. *head = *tail = fi;
  116. else
  117. *tail = (*tail)->next =fi;
  118. }
  119. /**
  120. * Free the memory for all entries in a list of file_info structs.
  121. */
  122. static void
  123. file_info_list_free(struct file_info *fi)
  124. {
  125. while (fi) {
  126. struct file_info *fl;
  127. fl=fi; fi=fi->next;
  128. file_info_free(fl);
  129. }
  130. }
  131. static void
  132. file_treewalk_feed(const char *dir, int fd_out)
  133. {
  134. struct treeroot *tree;
  135. struct treenode *node;
  136. struct file_info *fi;
  137. struct file_info *symlist = NULL;
  138. struct file_info *symlist_end = NULL;
  139. tree = treewalk_open(dir, TREEWALK_NONE, NULL);
  140. for (node = treewalk_node(tree); node ; node = treewalk_next(tree)) {
  141. const char *virtname = treenode_get_virtname(node);
  142. char *nodename;
  143. if (strncmp(virtname, BUILDCONTROLDIR, strlen(BUILDCONTROLDIR)) == 0)
  144. continue;
  145. nodename = str_fmt("./%s", virtname);
  146. if (strchr(nodename, '\n'))
  147. ohshit(_("newline not allowed in pathname '%s'"), nodename);
  148. /* We need to reorder the files so we can make sure that symlinks
  149. * will not appear before their target. */
  150. if (S_ISLNK(treenode_get_mode(node))) {
  151. fi = file_info_new(nodename);
  152. file_info_list_append(&symlist, &symlist_end, fi);
  153. } else {
  154. if (fd_write(fd_out, nodename, strlen(nodename) + 1) < 0)
  155. ohshite(_("failed to write filename to tar pipe (%s)"),
  156. _("data member"));
  157. }
  158. free(nodename);
  159. }
  160. treewalk_close(tree);
  161. for (fi = symlist; fi; fi = fi->next)
  162. if (fd_write(fd_out, fi->fn, strlen(fi->fn) + 1) < 0)
  163. ohshite(_("failed to write filename to tar pipe (%s)"), _("data member"));
  164. file_info_list_free(symlist);
  165. }
  166. static const char *const maintainerscripts[] = {
  167. PREINSTFILE,
  168. POSTINSTFILE,
  169. PRERMFILE,
  170. POSTRMFILE,
  171. NULL,
  172. };
  173. /**
  174. * Check control directory and file permissions.
  175. */
  176. static void
  177. check_file_perms(const char *ctrldir)
  178. {
  179. struct varbuf path = VARBUF_INIT;
  180. const char *const *mscriptp;
  181. struct stat mscriptstab;
  182. varbuf_printf(&path, "%s/", ctrldir);
  183. if (lstat(path.buf, &mscriptstab))
  184. ohshite(_("unable to stat control directory"));
  185. if (!S_ISDIR(mscriptstab.st_mode))
  186. ohshit(_("control directory is not a directory"));
  187. if ((mscriptstab.st_mode & 07757) != 0755)
  188. ohshit(_("control directory has bad permissions %03lo "
  189. "(must be >=0755 and <=0775)"),
  190. (unsigned long)(mscriptstab.st_mode & 07777));
  191. for (mscriptp = maintainerscripts; *mscriptp; mscriptp++) {
  192. varbuf_reset(&path);
  193. varbuf_printf(&path, "%s/%s", ctrldir, *mscriptp);
  194. if (!lstat(path.buf, &mscriptstab)) {
  195. if (S_ISLNK(mscriptstab.st_mode))
  196. continue;
  197. if (!S_ISREG(mscriptstab.st_mode))
  198. ohshit(_("maintainer script '%.50s' is not a plain file or symlink"),
  199. *mscriptp);
  200. if ((mscriptstab.st_mode & 07557) != 0555)
  201. ohshit(_("maintainer script '%.50s' has bad permissions %03lo "
  202. "(must be >=0555 and <=0775)"),
  203. *mscriptp, (unsigned long)(mscriptstab.st_mode & 07777));
  204. } else if (errno != ENOENT) {
  205. ohshite(_("maintainer script '%.50s' is not stattable"), *mscriptp);
  206. }
  207. }
  208. varbuf_destroy(&path);
  209. }
  210. /**
  211. * Check if conffiles contains sane information.
  212. */
  213. static void
  214. check_conffiles(const char *ctrldir, const char *rootdir)
  215. {
  216. FILE *cf;
  217. struct varbuf controlfile = VARBUF_INIT;
  218. char conffilename[MAXCONFFILENAME + 1];
  219. struct file_info *conffiles_head = NULL;
  220. struct file_info *conffiles_tail = NULL;
  221. varbuf_printf(&controlfile, "%s/%s", ctrldir, CONFFILESFILE);
  222. cf = fopen(controlfile.buf, "r");
  223. if (cf == NULL) {
  224. if (errno == ENOENT)
  225. return;
  226. ohshite(_("error opening conffiles file"));
  227. }
  228. while (fgets(conffilename, MAXCONFFILENAME + 1, cf)) {
  229. struct stat controlstab;
  230. int n;
  231. n = strlen(conffilename);
  232. if (!n)
  233. ohshite(_("empty string from fgets reading conffiles"));
  234. if (conffilename[n - 1] != '\n')
  235. ohshit(_("conffile name '%s' is too long, or missing final newline"),
  236. conffilename);
  237. conffilename[n - 1] = '\0';
  238. varbuf_reset(&controlfile);
  239. varbuf_printf(&controlfile, "%s/%s", rootdir, conffilename);
  240. if (lstat(controlfile.buf, &controlstab)) {
  241. if (errno == ENOENT) {
  242. if ((n > 1) && c_isspace(conffilename[n - 2]))
  243. warning(_("conffile filename '%s' contains trailing white spaces"),
  244. conffilename);
  245. ohshit(_("conffile '%.250s' does not appear in package"), conffilename);
  246. } else
  247. ohshite(_("conffile '%.250s' is not stattable"), conffilename);
  248. } else if (!S_ISREG(controlstab.st_mode)) {
  249. warning(_("conffile '%s' is not a plain file"), conffilename);
  250. }
  251. if (file_info_find_name(conffiles_head, conffilename)) {
  252. warning(_("conffile name '%s' is duplicated"), conffilename);
  253. } else {
  254. struct file_info *conffile;
  255. conffile = file_info_new(conffilename);
  256. file_info_list_append(&conffiles_head, &conffiles_tail, conffile);
  257. }
  258. }
  259. file_info_list_free(conffiles_head);
  260. varbuf_destroy(&controlfile);
  261. if (ferror(cf))
  262. ohshite(_("error reading conffiles file"));
  263. fclose(cf);
  264. }
  265. /**
  266. * Check the control file.
  267. *
  268. * @param dir The directory from where to build the binary package.
  269. * @return The pkginfo struct from the parsed control file.
  270. */
  271. static struct pkginfo *
  272. check_control_file(const char *ctrldir)
  273. {
  274. struct pkginfo *pkg;
  275. char *controlfile;
  276. controlfile = str_fmt("%s/%s", ctrldir, CONTROLFILE);
  277. parsedb(controlfile, pdb_parse_binary, &pkg);
  278. if (strspn(pkg->set->name, "abcdefghijklmnopqrstuvwxyz0123456789+-.") !=
  279. strlen(pkg->set->name))
  280. ohshit(_("package name has characters that aren't lowercase alphanums or '-+.'"));
  281. if (pkg->available.arch->type == DPKG_ARCH_NONE ||
  282. pkg->available.arch->type == DPKG_ARCH_EMPTY)
  283. ohshit(_("package architecture is missing or empty"));
  284. if (pkg->priority == PKG_PRIO_OTHER)
  285. warning(_("'%s' contains user-defined Priority value '%s'"),
  286. controlfile, pkg->otherpriority);
  287. free(controlfile);
  288. return pkg;
  289. }
  290. /**
  291. * Perform some sanity checks on the to-be-built package control area.
  292. *
  293. * @param dir The directory from where to build the binary package.
  294. * @return The pkginfo struct from the parsed control file.
  295. */
  296. static struct pkginfo *
  297. check_control_area(const char *ctrldir, const char *rootdir)
  298. {
  299. struct pkginfo *pkg;
  300. int warns;
  301. /* Start by reading in the control file so we can check its contents. */
  302. pkg = check_control_file(ctrldir);
  303. check_file_perms(ctrldir);
  304. check_conffiles(ctrldir, rootdir);
  305. warns = warning_get_count();
  306. if (warns)
  307. warning(P_("ignoring %d warning about the control file(s)",
  308. "ignoring %d warnings about the control file(s)", warns),
  309. warns);
  310. return pkg;
  311. }
  312. /**
  313. * Generate the pathname for the destination binary package.
  314. *
  315. * If the pathname cannot be computed, because the destination is a directory,
  316. * then NULL will be returned.
  317. *
  318. * @param dir The directory from where to build the binary package.
  319. * @param dest The destination name, either a file or directory name.
  320. * @return The pathname for the package being built.
  321. */
  322. static char *
  323. gen_dest_pathname(const char *dir, const char *dest)
  324. {
  325. if (dest) {
  326. struct stat dest_stab;
  327. if (stat(dest, &dest_stab)) {
  328. if (errno != ENOENT)
  329. ohshite(_("unable to check for existence of archive '%.250s'"), dest);
  330. } else if (S_ISDIR(dest_stab.st_mode)) {
  331. /* Need to compute the destination name from the package control file. */
  332. return NULL;
  333. }
  334. return m_strdup(dest);
  335. } else {
  336. char *pathname;
  337. pathname = m_malloc(strlen(dir) + sizeof(DEBEXT));
  338. strcpy(pathname, dir);
  339. path_trim_slash_slashdot(pathname);
  340. strcat(pathname, DEBEXT);
  341. return pathname;
  342. }
  343. }
  344. /**
  345. * Generate the pathname for the destination binary package from control file.
  346. *
  347. * @return The pathname for the package being built.
  348. */
  349. static char *
  350. gen_dest_pathname_from_pkg(const char *dir, struct pkginfo *pkg)
  351. {
  352. return str_fmt("%s/%s_%s_%s%s", dir, pkg->set->name,
  353. versiondescribe(&pkg->available.version, vdew_never),
  354. pkg->available.arch->name, DEBEXT);
  355. }
  356. typedef void filenames_feed_func(const char *dir, int fd_out);
  357. /**
  358. * Pack the contents of a directory into a tarball.
  359. */
  360. static void
  361. tarball_pack(const char *dir, filenames_feed_func *tar_filenames_feeder,
  362. time_t timestamp,
  363. struct compress_params *tar_compress_params, int fd_out)
  364. {
  365. int pipe_filenames[2], pipe_tarball[2];
  366. pid_t pid_tar, pid_comp;
  367. /* Fork off a tar. We will feed it a list of filenames on stdin later. */
  368. m_pipe(pipe_filenames);
  369. m_pipe(pipe_tarball);
  370. pid_tar = subproc_fork();
  371. if (pid_tar == 0) {
  372. char mtime[50];
  373. m_dup2(pipe_filenames[0], 0);
  374. close(pipe_filenames[0]);
  375. close(pipe_filenames[1]);
  376. m_dup2(pipe_tarball[1], 1);
  377. close(pipe_tarball[0]);
  378. close(pipe_tarball[1]);
  379. if (chdir(dir))
  380. ohshite(_("failed to chdir to '%.255s'"), dir);
  381. snprintf(mtime, sizeof(mtime), "@%ld", timestamp);
  382. execlp(TAR, "tar", "-cf", "-", "--format=gnu",
  383. "--mtime", mtime, "--clamp-mtime",
  384. "--null", "--no-unquote",
  385. "--no-recursion", "-T", "-", NULL);
  386. ohshite(_("unable to execute %s (%s)"), "tar -cf", TAR);
  387. }
  388. close(pipe_filenames[0]);
  389. close(pipe_tarball[1]);
  390. /* Of course we should not forget to compress the archive as well. */
  391. pid_comp = subproc_fork();
  392. if (pid_comp == 0) {
  393. close(pipe_filenames[1]);
  394. compress_filter(tar_compress_params, pipe_tarball[0], fd_out,
  395. _("compressing tar member"));
  396. exit(0);
  397. }
  398. close(pipe_tarball[0]);
  399. /* All the pipes are set, now lets start feeding filenames to tar. */
  400. tar_filenames_feeder(dir, pipe_filenames[1]);
  401. /* All done, clean up wait for tar and <compress> to finish their job. */
  402. close(pipe_filenames[1]);
  403. subproc_reap(pid_comp, _("<compress> from tar -cf"), 0);
  404. subproc_reap(pid_tar, "tar -cf", 0);
  405. }
  406. static time_t
  407. parse_timestamp(const char *value)
  408. {
  409. time_t timestamp;
  410. char *end;
  411. errno = 0;
  412. timestamp = strtol(value, &end, 10);
  413. if (value == end || *end || errno != 0)
  414. ohshite(_("unable to parse timestamp '%.255s'"), value);
  415. return timestamp;
  416. }
  417. /**
  418. * Overly complex function that builds a .deb file.
  419. */
  420. int
  421. do_build(const char *const *argv)
  422. {
  423. struct compress_params control_compress_params;
  424. struct dpkg_error err;
  425. struct dpkg_ar *ar;
  426. time_t timestamp;
  427. const char *timestamp_str;
  428. const char *dir, *dest;
  429. char *ctrldir;
  430. char *debar;
  431. char *tfbuf;
  432. int gzfd;
  433. /* Decode our arguments. */
  434. dir = *argv++;
  435. if (!dir)
  436. badusage(_("--%s needs a <directory> argument"), cipaction->olong);
  437. dest = *argv++;
  438. if (dest && *argv)
  439. badusage(_("--%s takes at most two arguments"), cipaction->olong);
  440. debar = gen_dest_pathname(dir, dest);
  441. ctrldir = str_fmt("%s/%s", dir, BUILDCONTROLDIR);
  442. /* Perform some sanity checks on the to-be-build package. */
  443. if (nocheckflag) {
  444. if (debar == NULL)
  445. ohshit(_("target is directory - cannot skip control file check"));
  446. warning(_("not checking contents of control area"));
  447. info(_("building an unknown package in '%s'."), debar);
  448. } else {
  449. struct pkginfo *pkg;
  450. pkg = check_control_area(ctrldir, dir);
  451. if (debar == NULL)
  452. debar = gen_dest_pathname_from_pkg(dest, pkg);
  453. info(_("building package '%s' in '%s'."), pkg->set->name, debar);
  454. }
  455. m_output(stdout, _("<standard output>"));
  456. timestamp_str = getenv("SOURCE_DATE_EPOCH");
  457. if (timestamp_str)
  458. timestamp = parse_timestamp(timestamp_str);
  459. else
  460. timestamp = time(NULL);
  461. /* Now that we have verified everything it is time to actually
  462. * build something. Let's start by making the ar-wrapper. */
  463. ar = dpkg_ar_create(debar, 0644);
  464. dpkg_ar_set_mtime(ar, timestamp);
  465. unsetenv("TAR_OPTIONS");
  466. /* Create a temporary file to store the control data in. Immediately
  467. * unlink our temporary file so others can't mess with it. */
  468. tfbuf = path_make_temp_template("dpkg-deb");
  469. gzfd = mkstemp(tfbuf);
  470. if (gzfd == -1)
  471. ohshite(_("failed to make temporary file (%s)"), _("control member"));
  472. /* Make sure it's gone, the fd will remain until we close it. */
  473. if (unlink(tfbuf))
  474. ohshit(_("failed to unlink temporary file (%s), %s"), _("control member"),
  475. tfbuf);
  476. free(tfbuf);
  477. /* Select the compressor to use for our control archive. */
  478. if (opt_uniform_compression) {
  479. control_compress_params = compress_params;
  480. } else {
  481. control_compress_params.type = COMPRESSOR_TYPE_GZIP;
  482. control_compress_params.strategy = COMPRESSOR_STRATEGY_NONE;
  483. control_compress_params.level = -1;
  484. if (!compressor_check_params(&control_compress_params, &err))
  485. internerr("invalid control member compressor params: %s", err.str);
  486. }
  487. /* Fork a tar to package the control-section of the package. */
  488. tarball_pack(ctrldir, control_treewalk_feed, timestamp,
  489. &control_compress_params, gzfd);
  490. free(ctrldir);
  491. if (lseek(gzfd, 0, SEEK_SET))
  492. ohshite(_("failed to rewind temporary file (%s)"), _("control member"));
  493. /* We have our first file for the ar-archive. Write a header for it
  494. * to the package and insert it. */
  495. if (deb_format.major == 0) {
  496. struct stat controlstab;
  497. char versionbuf[40];
  498. if (fstat(gzfd, &controlstab))
  499. ohshite(_("failed to stat temporary file (%s)"), _("control member"));
  500. sprintf(versionbuf, "%-8s\n%jd\n", OLDARCHIVEVERSION,
  501. (intmax_t)controlstab.st_size);
  502. if (fd_write(ar->fd, versionbuf, strlen(versionbuf)) < 0)
  503. ohshite(_("error writing '%s'"), debar);
  504. if (fd_fd_copy(gzfd, ar->fd, -1, &err) < 0)
  505. ohshit(_("cannot copy '%s' into archive '%s': %s"), _("control member"),
  506. ar->name, err.str);
  507. } else if (deb_format.major == 2) {
  508. const char deb_magic[] = ARCHIVEVERSION "\n";
  509. char adminmember[16 + 1];
  510. sprintf(adminmember, "%s%s", ADMINMEMBER,
  511. compressor_get_extension(control_compress_params.type));
  512. dpkg_ar_put_magic(ar);
  513. dpkg_ar_member_put_mem(ar, DEBMAGIC, deb_magic, strlen(deb_magic));
  514. dpkg_ar_member_put_file(ar, adminmember, gzfd, -1);
  515. } else {
  516. internerr("unknown deb format version %d.%d", deb_format.major, deb_format.minor);
  517. }
  518. close(gzfd);
  519. /* Control is done, now we need to archive the data. */
  520. if (deb_format.major == 0) {
  521. /* In old format, the data member is just concatenated after the
  522. * control member, so we do not need a temporary file and can use
  523. * the compression file descriptor. */
  524. gzfd = ar->fd;
  525. } else if (deb_format.major == 2) {
  526. /* Start by creating a new temporary file. Immediately unlink the
  527. * temporary file so others can't mess with it. */
  528. tfbuf = path_make_temp_template("dpkg-deb");
  529. gzfd = mkstemp(tfbuf);
  530. if (gzfd == -1)
  531. ohshite(_("failed to make temporary file (%s)"), _("data member"));
  532. /* Make sure it's gone, the fd will remain until we close it. */
  533. if (unlink(tfbuf))
  534. ohshit(_("failed to unlink temporary file (%s), %s"), _("data member"),
  535. tfbuf);
  536. free(tfbuf);
  537. } else {
  538. internerr("unknown deb format version %d.%d", deb_format.major, deb_format.minor);
  539. }
  540. /* Pack the directory into a tarball, feeding files from the callback. */
  541. tarball_pack(dir, file_treewalk_feed, timestamp, &compress_params, gzfd);
  542. /* Okay, we have data.tar as well now, add it to the ar wrapper. */
  543. if (deb_format.major == 2) {
  544. char datamember[16 + 1];
  545. sprintf(datamember, "%s%s", DATAMEMBER,
  546. compressor_get_extension(compress_params.type));
  547. if (lseek(gzfd, 0, SEEK_SET))
  548. ohshite(_("failed to rewind temporary file (%s)"), _("data member"));
  549. dpkg_ar_member_put_file(ar, datamember, gzfd, -1);
  550. close(gzfd);
  551. }
  552. if (fsync(ar->fd))
  553. ohshite(_("unable to sync file '%s'"), ar->name);
  554. dpkg_ar_close(ar);
  555. free(debar);
  556. return 0;
  557. }