From: Nathan Wagner Date: Fri, 15 Feb 2019 13:55:46 +0000 (+0000) Subject: rework zpm-add X-Git-Tag: v0.5.0~9 X-Git-Url: https://pd.if.org/git/?p=zpackage;a=commitdiff_plain;h=86d735d52280359df4896d5c542ddfbe33d8df7b rework zpm-add --- diff --git a/Makefile b/Makefile index 6358c20..c564012 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ lib/jsw/jsw_rbtree.c JSWOBJ=$(JSWSRC:%.c=%.o) LIBZPMSRC=sha256.c db.c compress.c uncompress.c zpm.c zpm_hash.c \ foreach_path.c vercmp.c findpkg.c quote.c dbquery.c script_hash.c \ - parse.c integ.c seterror.c notes.c + parse.c integ.c seterror.c notes.c createpkg.c LIBZPMOBJ=$(addprefix lib/, $(LIBZPMSRC:%.c=%.o)) diff --git a/doc/zpm-add.8 b/doc/zpm-add.8 new file mode 100644 index 0000000..b55f40c --- /dev/null +++ b/doc/zpm-add.8 @@ -0,0 +1,88 @@ +.TH zpm-add 8 2019-02-15 "ZPM 0.4" +.SH NAME +zpm-add \- add files to a package +.SH SYNOPSIS +.B zpm add +.RI -f packagefile +.B [ -icCNschlrvxz ] +.BI "[ -F " type " ]" +.BI "[ -H " hash " ]" +.BI "[ -M " mtime " ]" +.BI "[ -P " prefix " ]" +.BI "[ -S " stripprefix " ]" +.BI "[ -s " n " ]" +.BI "[ -T " target " ]" +.BI "[ -f " path " ]" +.BI "[ -g " group " ]" +.BI "[ -u " user " ]" +.BI "[ -m " mode " ]" +.BI "[ -p " package " ]" +.IR path ... +.SH DESCRIPTION +\fBzpm-add\fR adds files to a zpm package. +The package file must exist, and the package in the package file +must exist. File metadata is taken from the filesystem, unless +overridden by command line options. +.PP +If the package name is not given with the \-p option, it will be inferred. +from the package file name. The package file name must be parsable as a +complete package id. +.SH OPTIONS +.TP +.B \-i +Create the package if necessary, create the package file if it does not +exist. +.TP +.B \-C +mark the package as complete when finished. Normally a package +is marked as incomplete after adding files. +.TP +.B \-c +Mark added files as config files. +.TP +.BI \-p pkgid +Add files to the named package. The package will be looked up as if by +zpm-findpkg. Overrides \-i. +.TP +.BI \-F type +force added files to be the type. See Non-Existent Files. +.TP +.BI \-H hash_value +specify the hash value of a file. See Non-Existent Files. +.TP +.BI \-M mtime +specify mtime. for a non-existent file, if not specified here, the current +time will be used. +.TP +.BI \-m mode +Directly set the mode of added files. If not set, the mode will be taken +from the filesystem. +.TP +.B \-N +Don't add any file content for regular files. +.TP +.BI \-P prefix +Prefix added file paths with the given prefix. No '/' is added, +so the prefix should include a trailing '/' if the prefix is intended +to be a directory. +.TP +.B \-r +recursively add paths underneath directories +.SH EXAMPLES +.TP +zpm-add -f passwd-1.0-1.zpm passwd-1.0-1 /etc/passwd +Add the /etc/passwd file to the passwd-1.0-1 package. +.SH EXIT STATUS +0 if adding files was successful +1 if adding files failed if -x is not given +255 if adding files failed and -x is given +.SH FILES +None +.SH ENVIRONMENT +None +.SH AUTHOR +Nathan Wagner +.SH SEE ALSO +.BR zpm (8) +.BR zpm-packagehash (8) +.BR zpm-addfile (8) diff --git a/lib/dbquery.c b/lib/dbquery.c index d0edecc..f68eb4a 100644 --- a/lib/dbquery.c +++ b/lib/dbquery.c @@ -40,6 +40,7 @@ sqlite3_stmt *zpm_dbqueryv(struct zpm *zpm, char *query, va_list args) { zpm->error = rv; return 0; } + sqlite3_free(sql); return st; } diff --git a/src/add.c b/src/add.c index 86b289d..1be34e8 100644 --- a/src/add.c +++ b/src/add.c @@ -21,7 +21,7 @@ struct opts { int complete, addcontent, isconfig, opt_l, recursive, verbose; int followsymlinks; int xargs, noclear; - int striparg; + int striparg, init; mode_t clmode; char *cltype, *clhash, *clmtime, *prefix, *strip, *cltarget; @@ -381,6 +381,11 @@ int main(int ac, char **av) { struct opts opt = { 0 }; int i; int option; + char *pkgstr = 0, *pkgid = 0; + + char package[128]; + char version[64]; + int release; char hash[ZPM_HASH_STRLEN+1]; @@ -392,8 +397,10 @@ int main(int ac, char **av) { opt.addcontent = 1; - while ((option = getopt(ac, av, "CF:H:M:NP:S:T:cf:g:hlm:ru:vxz")) != -1) { + while ((option = getopt(ac, av, "iCF:H:M:NP:S:T:cf:g:hlm:ru:vxzp:")) != -1) { switch (option) { + case 'f': dbfile = optarg; break; + case 'i': opt.init = 1; break; case 'C': opt.complete = 1; break; case 'F': opt.cltype = optarg; break; case 'H': opt.clhash = optarg; break; @@ -404,7 +411,6 @@ int main(int ac, char **av) { case 's': opt.striparg = 1; break; case 'T': opt.cltarget = optarg; break; case 'c': opt.isconfig = 1; break; - case 'f': dbfile = optarg; break; case 'g': opt.clgroup = optarg; break; case 'h': opt.followsymlinks = 1; break; case 'l': opt.opt_l = 1; break; @@ -414,6 +420,7 @@ int main(int ac, char **av) { case 'v': opt.verbose++; break; case 'x': opt.xargs = 1; dieval = 255; break; case 'z': opt.noclear = 1; break; + case 'p': pkgstr = optarg; break; default: exit(EXIT_FAILURE); break; @@ -424,10 +431,20 @@ int main(int ac, char **av) { exit(EXIT_FAILURE); } - if (!zpm_open(&zpm, dbfile)) { - die("can't open zpm db %s", dbfile); + if (opt.init) { + if (!zpm_init(&zpm, dbfile)) { + die("can't open zpm db %s", dbfile); + } + if (opt.verbose) { + fprintf(stderr, "inited %s\n", dbfile); + } + } else { + if (!zpm_open(&zpm, dbfile)) { + die("can't open zpm db %s", dbfile); + } } + #if 0 i = sqlite3_config(SQLITE_CONFIG_MMAP_SIZE,98222080); if (i != SQLITE_OK) { @@ -435,19 +452,28 @@ int main(int ac, char **av) { } #endif - /* package is first arg */ - char *pkgstr; - char *pkgid; - pkgstr = av[optind++]; + if (!pkgstr) { + pkgstr = dbfile; + } pkgid = zpm_findpkg(&zpm, pkgstr, NULL); if (!pkgid) { - die("package %s not found\n", pkgstr); + int rv; + if (opt.init) { + rv = zpm_parse_package(pkgstr, package, version, &release); + if (rv != 3) { + die("incomplete package string '%s'\n", pkgstr); + } else { + rv = zpm_create_package(&zpm, package, version, release); + pkgid = zpm_findpkg(&zpm, pkgstr, NULL); + if (!rv) { + die("unable to create package %s\n", pkgstr); + } + } + } else { + die("package %s not found\n", pkgstr); + } } - char package[128]; - char version[64]; - int release; - zpm_parse_package(pkgid, package, version, &release); opt.package = package; opt.version = version; diff --git a/t/add.t b/t/add.t index 891a22d..0305c8d 100755 --- a/t/add.t +++ b/t/add.t @@ -7,7 +7,7 @@ PF=test.db -plan 32 +plan 34 require rm -rf tmp require mkdir tmp @@ -20,7 +20,7 @@ pkgid=zpmtest-1.0-1 PF=zpmtest-1.0-1.zpm require -v zpm newpackage -C $pkgid -require -v zpm add -vvv -f $PF $pkgid foo +require -v zpm add -vvv -f $PF -p $pkgid foo h=$(zpm hash foo) require -v zpm extract -f zpmtest-1.0-1.zpm $h foo2 h2=$(zpm hash foo2) @@ -36,7 +36,7 @@ diag "$pkglist" rm -f $PF require zpm newpackage -f $PF -C $pkgid -require zpm add -f $PF zpmtest foo +require zpm add -f $PF -p zpmtest foo rm -f foo2 require zpm extract -f $PF $h foo2 h2=$(zpm hash foo2) @@ -54,19 +54,19 @@ rm -f $PF mkdir subdir touch subdir/foo require zpm newpackage -f $PF -C $pkgid -require -v zpm add -f $PF -S subdir zpmtest subdir/foo +require -v zpm add -f $PF -S subdir -p zpmtest subdir/foo fn=$(zpm showpkg $PF | awk '{print $4}') okstreq "$fn" "/foo" file foo in package prefix striped rm -f $PF require zpm newpackage -f $PF -C $pkgid -require zpm add -f $PF zpmtest foo +require zpm add -f $PF -p zpmtest foo ph=$(zpm pkg -f $PF zpmtest hash) okstreq "$ph" "" package hash empty mtime=$(zpm pkg -f $PF zpmtest build_time) okstreq "$ph" "" package mtime empty -zpm add -C -f $PF zpmtest subdir/foo +zpm add -C -f $PF -p zpmtest subdir/foo okexit added file and completed package ph=$(zpm pkg -f $PF zpmtest hash) test -n "$ph" @@ -77,12 +77,16 @@ test -n "$mtime" okexit package mtime not empty touch subdir/bar -require zpm add -f $PF zpmtest subdir/bar +require zpm add -f $PF -p zpmtest subdir/bar ph=$(zpm pkg -f $PF zpmtest hash) okstreq "$ph" "" package hash cleared mtime=$(zpm pkg -f $PF zpmtest build_time) okstreq "$ph" "" package mtime cleared +echo junk data > subdir/baz +require zpm add -f $PF subdir/baz +rm $PF +require zpm add -i -f $PF subdir/baz finish diff --git a/t/install.t b/t/install.t index b1ae113..e9c05aa 100755 --- a/t/install.t +++ b/t/install.t @@ -18,7 +18,7 @@ newpkg() { tryrun zpm newpackage -f $pkgid.zpm $pkgid if [ $? -eq 0 ]; then shift - tryrun zpm add -u $owner -g $group -f $pkgid.zpm $pkgid "$@" + tryrun zpm add -u $owner -g $group -f $pkgid.zpm -p $pkgid "$@" return $? else skip 1 not adding files init failed @@ -53,7 +53,7 @@ PF=$pkgid.zpm #require zpm init $PF #require zpm newpackage -f $PF $pkgid -#require zpm add -f $PF $pkgid /bin/true +#require zpm add -f $PF -p $pkgid /bin/true # # install via syncfs @@ -97,7 +97,7 @@ newver=$(zpm pkg -f $PF itest version) okstreq "$newver" "2.0" "have updated version" rm -f test.out -tryrun zpm add -f $PF itest /bin/false +tryrun zpm add -f $PF -p itest /bin/false if [ $? -ne 0 ]; then diag h2 cat test.out | diagstdin diff --git a/t/pathmod.t b/t/pathmod.t index 47575e6..e61b114 100755 --- a/t/pathmod.t +++ b/t/pathmod.t @@ -18,7 +18,7 @@ newpkg() { tryrun zpm newpackage -f $pkgid.zpm $pkgid if [ $? -eq 0 ]; then shift - tryrun zpm add -u $owner -g $group -f $pkgid.zpm $pkgid "$@" + tryrun zpm add -u $owner -g $group -f $pkgid.zpm -p $pkgid "$@" return $? else skip 1 not adding files init failed diff --git a/t/update.t b/t/update.t index d97f0be..3215515 100755 --- a/t/update.t +++ b/t/update.t @@ -18,7 +18,7 @@ newpkg() { tryrun zpm newpackage -f $pkgid.zpm $pkgid if [ $? -eq 0 ]; then shift - tryrun zpm add -u $owner -g $group -f $pkgid.zpm $pkgid "$@" + tryrun zpm add -u $owner -g $group -f $pkgid.zpm -p $pkgid "$@" return $? else skip 1 not adding files init failed @@ -52,7 +52,7 @@ okexit setup package $pkgid PF=$pkgid.zpm require mkdir etc echo foo > etc/conf -zpm add -f $PF -C -c $pkgid etc/conf +zpm add -f $PF -C -c -p $pkgid etc/conf okexit added foo conf isconf=$(zpm pkgfile -f $PF $pkgid /etc/conf configuration) okstreq $isconf 1 etc/conf 1.0 is config file @@ -62,7 +62,7 @@ newpkg $pkgid /bin/true okexit setup package $pkgid PF=$pkgid.zpm echo bar > etc/conf -zpm add -f $PF -C -c $pkgid etc/conf +zpm add -f $PF -C -c -p $pkgid etc/conf okexit added bar conf isconf=$(zpm pkgfile -f $PF $pkgid /etc/conf configuration) okstreq $isconf 1 etc/conf 2.0 is config file @@ -72,7 +72,7 @@ newpkg $pkgid /bin/true okexit setup package $pkgid PF=$pkgid.zpm echo baz > etc/conf -zpm add -f $PF -C -c $pkgid etc/conf +zpm add -f $PF -C -c -p $pkgid etc/conf okexit added baz conf isconf=$(zpm pkgfile -f $PF $pkgid /etc/conf configuration) okstreq $isconf 1 etc/conf 3.0 is config file diff --git a/zpm.h b/zpm.h index 6cca057..5fc450f 100644 --- a/zpm.h +++ b/zpm.h @@ -153,8 +153,9 @@ int zpm_package(struct zpm *zp, int n); /* get file information */ int zpm_stat(struct zpm *z, struct zpm_file *f, int n); -/* will also set the package context to the new package */ -int zpm_newpkg(struct zpm *z, char *base, char *version, int release); +//int zpm_newpkg(struct zpm *z, char *base, char *version, int release); +int zpm_create_package(struct zpm *zpm, char *name, char *ver, int rel); +int zpm_create_pkgid(struct zpm *zpm, char *pkgstr); /* transactions */ int zpm_begin(struct zpm *z);