static char * trig_get_filename(const char *dir, const char *filename) { char *path; m_asprintf(&path, "%s/%s", dir, filename); return path; }
static char * get_prefix_name(struct tar_header *h) { char *path; m_asprintf(&path, "%.*s/%.*s", (int)sizeof(h->prefix), h->prefix, (int)sizeof(h->name), h->name); return path; }
/** * Generate the pathname for the to-be-built package. * * @return The pathname for the package being built. */ static char * pkg_get_pathname(const char *dir, struct pkginfo *pkg) { char *path; const char *versionstring, *arch_sep; versionstring = versiondescribe(&pkg->available.version, vdew_never); arch_sep = pkg->available.arch->type == arch_none ? "" : "_"; m_asprintf(&path, "%s/%s_%s%s%s%s", dir, pkg->set->name, versionstring, arch_sep, pkg->available.arch->name, DEBEXT); return path; }
int dpkg_put_errno(struct dpkg_error *err, const char *fmt, ...) { va_list args; char *new_fmt; m_asprintf(&new_fmt, "%s (%s)", fmt, strerror(errno)); va_start(args, fmt); dpkg_error_set(err, DPKG_MSG_ERROR, new_fmt, args); va_end(args); free(new_fmt); return -1; }
/* FIXME: Ideally we'd use openat() here, to avoid the path mangling, but * it's not widely available yet, so this will do for now. */ static void dir_file_sync(const char *dir, const char *filename) { char *path; int fd; m_asprintf(&path, "%s/%s", dir, filename); fd = open(path, O_WRONLY); if (fd < 0) ohshite(_("unable to open file '%s'"), path); if (fsync(fd)) ohshite(_("unable to sync file '%s'"), path); if (close(fd)) ohshite(_("unable to close file '%s'"), path); free(path); }
int do_showinfo(const char *const *argv) { const char *debar, *dir; char *controlfile; struct pkginfo *pkg; struct pkg_format_node *fmt = pkg_format_parse(showformat); if (!fmt) ohshit(_("Error in format")); info_prepare(&argv, &debar, &dir, 1); m_asprintf(&controlfile, "%s/%s", dir, CONTROLFILE); parsedb(controlfile, pdb_parse_binary | pdb_ignorefiles, &pkg); pkg_format_show(fmt, pkg, &pkg->available); pkg_format_free(fmt); free(controlfile); return 0; }
/** * Perform some sanity checks on the to-be-built package. * * @return The pkginfo struct from the parsed control file. */ static struct pkginfo * check_new_pkg(const char *dir) { struct pkginfo *pkg; struct arbitraryfield *field; char *controlfile; int warns; /* Start by reading in the control file so we can check its contents. */ m_asprintf(&controlfile, "%s/%s/%s", dir, BUILDCONTROLDIR, CONTROLFILE); parsedb(controlfile, pdb_parse_binary, &pkg); if (strspn(pkg->set->name, "abcdefghijklmnopqrstuvwxyz0123456789+-.") != strlen(pkg->set->name)) ohshit(_("package name has characters that aren't lowercase alphanums or `-+.'")); if (pkg->priority == pri_other) warning(_("'%s' contains user-defined Priority value '%s'"), controlfile, pkg->otherpriority); for (field = pkg->available.arbs; field; field = field->next) { if (known_arbitrary_field(field)) continue; warning(_("'%s' contains user-defined field '%s'"), controlfile, field->name); } free(controlfile); check_file_perms(dir); check_conffiles(dir); warns = warning_get_count(); if (warns) warning(P_("ignoring %d warning about the control file(s)\n", "ignoring %d warnings about the control file(s)\n", warns), warns); return pkg; }
static void info_field(const char *debar, const char *dir, const char *const *fields, bool showfieldname) { FILE *cc; char *controlfile; char fieldname[MAXFIELDNAME+1]; char *pf; const char *const *fp; int c, lno, fnl; bool doing; m_asprintf(&controlfile, "%s/%s", dir, CONTROLFILE); cc = fopen(controlfile, "r"); if (!cc) ohshite(_("could not open the `control' component")); doing = true; lno = 1; for (;;) { c = getc(cc); if (c == EOF) { doing = false; break; } if (c == '\n') { lno++; doing = true; continue; } if (!isspace(c)) { for (pf=fieldname, fnl=0; fnl <= MAXFIELDNAME && c!=EOF && !isspace(c) && c!=':'; c= getc(cc)) { *pf++= c; fnl++; } *pf = '\0'; doing= fnl >= MAXFIELDNAME || c=='\n' || c==EOF; for (fp=fields; !doing && *fp; fp++) if (strcasecmp(*fp, fieldname) == 0) doing = true; if (showfieldname) { if (doing) fputs(fieldname,stdout); } else { if (c==':') c= getc(cc); while (c != '\n' && isspace(c)) c= getc(cc); } } for(;;) { if (c == EOF) break; if (doing) putc(c,stdout); if (c == '\n') { lno++; break; } c= getc(cc); } if (c == EOF) break; } if (ferror(cc)) ohshite(_("failed during read of `control' component")); if (fclose(cc)) ohshite(_("error closing the '%s' component"), CONTROLFILE); if (doing) putc('\n',stdout); m_output(stdout, _("<standard output>")); free(controlfile); }
static int mksplit(const char *file_src, const char *prefix, off_t maxpartsize, bool msdos) { int fd_src; struct stat st; char hash[MD5HASHLEN + 1]; char *package, *version, *arch; int nparts, curpart; off_t partsize; off_t cur_partsize, last_partsize; char *prefixdir = NULL, *msdos_prefix = NULL; struct varbuf file_dst = VARBUF_INIT; struct varbuf partmagic = VARBUF_INIT; struct varbuf partname = VARBUF_INIT; fd_src = open(file_src, O_RDONLY); if (fd_src < 0) ohshite(_("unable to open source file `%.250s'"), file_src); if (fstat(fd_src, &st)) ohshite(_("unable to fstat source file")); if (!S_ISREG(st.st_mode)) ohshit(_("source file `%.250s' not a plain file"), file_src); fd_md5(fd_src, hash, -1, "md5hash"); lseek(fd_src, 0, SEEK_SET); /* FIXME: Use libdpkg-deb. */ package = deb_field(file_src, "Package"); version = deb_field(file_src, "Version"); arch = deb_field(file_src, "Architecture"); partsize = maxpartsize - HEADERALLOWANCE; last_partsize = st.st_size % partsize; if (last_partsize == 0) last_partsize = partsize; nparts = (st.st_size + partsize - 1) / partsize; setvbuf(stdout, NULL, _IONBF, 0); printf(P_("Splitting package %s into %d part: ", "Splitting package %s into %d parts: ", nparts), package, nparts); if (msdos) { char *t; t = m_strdup(prefix); prefixdir = m_strdup(dirname(t)); free(t); msdos_prefix = m_strdup(path_basename(prefix)); prefix = clean_msdos_filename(msdos_prefix); } for (curpart = 1; curpart <= nparts; curpart++) { int fd_dst; varbuf_reset(&file_dst); /* Generate output filename. */ if (msdos) { char *refname; int prefix_max; m_asprintf(&refname, "%dof%d", curpart, nparts); prefix_max = max(8 - strlen(refname), 0); varbuf_printf(&file_dst, "%s/%.*s%.8s.deb", prefixdir, prefix_max, prefix, refname); free(refname); } else { varbuf_printf(&file_dst, "%s.%dof%d.deb", prefix, curpart, nparts); } if (curpart == nparts) cur_partsize = last_partsize; else cur_partsize = partsize; if (cur_partsize > maxpartsize) { ohshit(_("Header is too long, making part too long. " "Your package name or version\n" "numbers must be extraordinarily long, " "or something. Giving up.\n")); } /* Split the data. */ fd_dst = creat(file_dst.buf, 0644); if (fd_dst < 0) ohshite(_("unable to open file '%s'"), file_dst.buf); /* Write the ar header. */ dpkg_ar_put_magic(file_dst.buf, fd_dst); /* Write the debian-split part. */ varbuf_printf(&partmagic, "%s\n%s\n%s\n%s\n%jd\n%jd\n%d/%d\n%s\n", SPLITVERSION, package, version, hash, (intmax_t)st.st_size, (intmax_t)partsize, curpart, nparts, arch); dpkg_ar_member_put_mem(file_dst.buf, fd_dst, PARTMAGIC, partmagic.buf, partmagic.used); varbuf_reset(&partmagic); /* Write the data part. */ varbuf_printf(&partname, "data.%d", curpart); dpkg_ar_member_put_file(file_dst.buf, fd_dst, partname.buf, fd_src, cur_partsize); varbuf_reset(&partname); close(fd_dst); printf("%d ", curpart); } varbuf_destroy(&file_dst); varbuf_destroy(&partname); varbuf_destroy(&partmagic); free(prefixdir); free(msdos_prefix); close(fd_src); printf(_("done\n")); return 0; }
int do_auto(const char *const *argv) { const char *partfile; struct partinfo *refi, **partlist, *otherthispart; struct partqueue *pq; unsigned int i; int j; FILE *part; if (!opt_outputfile) badusage(_("--auto requires the use of the --output option")); if (!(partfile= *argv++) || *argv) badusage(_("--auto requires exactly one part file argument")); refi= nfmalloc(sizeof(struct partqueue)); part= fopen(partfile,"r"); if (!part) ohshite(_("unable to read part file `%.250s'"),partfile); if (!read_info(part,partfile,refi)) { if (!opt_npquiet) printf(_("File `%.250s' is not part of a multipart archive.\n"),partfile); m_output(stdout, _("<standard output>")); return 1; } fclose(part); scandepot(); partlist= nfmalloc(sizeof(struct partinfo*)*refi->maxpartn); for (i = 0; i < refi->maxpartn; i++) partlist[i] = NULL; for (pq= queue; pq; pq= pq->nextinqueue) { struct partinfo *npi, *pi = &pq->info; if (!partmatches(pi,refi)) continue; npi= nfmalloc(sizeof(struct partinfo)); mustgetpartinfo(pi->filename,npi); addtopartlist(partlist,npi,refi); } /* If we already have a copy of this version we ignore it and prefer the * new one, but we still want to delete the one in the depot, so we * save its partinfo (with the filename) for later. This also prevents * us from accidentally deleting the source file. */ otherthispart= partlist[refi->thispartn-1]; partlist[refi->thispartn-1]= refi; for (j=refi->maxpartn-1; j>=0 && partlist[j]; j--); if (j>=0) { int fd_src, fd_dst; int ap; char *p, *q; m_asprintf(&p, "%st.%lx", opt_depotdir, (long)getpid()); m_asprintf(&q, "%s%s.%jx.%x.%x", opt_depotdir, refi->md5sum, (intmax_t)refi->maxpartlen, refi->thispartn, refi->maxpartn); fd_src = open(partfile, O_RDONLY); if (fd_src < 0) ohshite(_("unable to reopen part file `%.250s'"), partfile); fd_dst = creat(p, 0644); if (fd_dst < 0) ohshite(_("unable to open new depot file `%.250s'"), p); fd_fd_copy(fd_src, fd_dst, refi->filesize, _("extracting split part")); if (fsync(fd_dst)) ohshite(_("unable to sync file '%s'"), p); if (close(fd_dst)) ohshite(_("unable to close file '%s'"), p); close(fd_src); if (rename(p,q)) ohshite(_("unable to rename new depot file `%.250s' to `%.250s'"),p,q); free(q); free(p); printf(_("Part %d of package %s filed (still want "),refi->thispartn,refi->package); /* There are still some parts missing. */ for (i=0, ap=0; i<refi->maxpartn; i++) if (!partlist[i]) printf("%s%d", !ap++ ? "" : i == (unsigned int)j ? _(" and ") : ", ", i + 1); printf(").\n"); dir_sync_path(opt_depotdir); } else { /* We have all the parts. */ reassemble(partlist, opt_outputfile); /* OK, delete all the parts (except the new one, which we never copied). */ partlist[refi->thispartn-1]= otherthispart; for (i=0; i<refi->maxpartn; i++) if (partlist[i]) if (unlink(partlist[i]->filename)) ohshite(_("unable to delete used-up depot file `%.250s'"),partlist[i]->filename); } m_output(stderr, _("<standard error>")); return 0; }