]> pd.if.org Git - zpackage/commitdiff
rework zpm-add
authorNathan Wagner <nw@hydaspes.if.org>
Fri, 15 Feb 2019 13:55:46 +0000 (13:55 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Fri, 15 Feb 2019 18:25:10 +0000 (18:25 +0000)
Makefile
doc/zpm-add.8 [new file with mode: 0644]
lib/dbquery.c
src/add.c
t/add.t
t/install.t
t/pathmod.t
t/update.t
zpm.h

index 6358c207a42a6a6d01d56eba0c22cfa3a6176509..c564012894b401b44be697f2d8adea0f52424a52 100644 (file)
--- 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 \
 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))
 
 
 LIBZPMOBJ=$(addprefix lib/, $(LIBZPMSRC:%.c=%.o))
 
diff --git a/doc/zpm-add.8 b/doc/zpm-add.8
new file mode 100644 (file)
index 0000000..b55f40c
--- /dev/null
@@ -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)
index d0edecc5bff6d34014fdbd98237b411839cd68c9..f68eb4ab2489c2bdf3a6b121cafee2822ac78e95 100644 (file)
@@ -40,6 +40,7 @@ sqlite3_stmt *zpm_dbqueryv(struct zpm *zpm, char *query, va_list args) {
                zpm->error = rv;
                return 0;
        }
                zpm->error = rv;
                return 0;
        }
+       sqlite3_free(sql);
 
        return st;
 }
 
        return st;
 }
index 86b289d9748d836aff391c7ef4f32f6f3d20bb4c..1be34e81805c0393971fff05f5d4230a0c728d59 100644 (file)
--- 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 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;
        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;
        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];
 
 
        char hash[ZPM_HASH_STRLEN+1];
 
@@ -392,8 +397,10 @@ int main(int ac, char **av) {
 
        opt.addcontent = 1;
 
 
        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) {
                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;
                        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 '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;
                        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 '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;
                        default:
                                  exit(EXIT_FAILURE);
                                  break;
@@ -424,10 +431,20 @@ int main(int ac, char **av) {
                exit(EXIT_FAILURE);
        }
 
                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) {
 #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
 
        }
 #endif
 
-       /* package is first arg */
-       char *pkgstr;
-       char *pkgid;
-       pkgstr = av[optind++];
+       if (!pkgstr) {
+               pkgstr = dbfile;
+       }
        pkgid = zpm_findpkg(&zpm, pkgstr, NULL);
        if (!pkgid) {
        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;
        zpm_parse_package(pkgid, package, version, &release);
        opt.package = package;
        opt.version = version;
diff --git a/t/add.t b/t/add.t
index 891a22d202889b8e47aa87ed1546e50e2d2e4af6..0305c8d823c0d554a2b6188bca5b807d61d6b741 100755 (executable)
--- a/t/add.t
+++ b/t/add.t
@@ -7,7 +7,7 @@
 
 PF=test.db
 
 
 PF=test.db
 
-plan 32
+plan 34
 
 require rm -rf tmp
 require mkdir tmp
 
 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
 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)
 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
 
 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)
 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
 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
 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
 
 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"
 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
 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
 
 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
 
 
 finish
 
index b1ae1138062011dbc3bf1cc0c63164c56adc9a3f..e9c05aa18d1e94de73580fd07cb81c595b42a4f0 100755 (executable)
@@ -18,7 +18,7 @@ newpkg() {
                tryrun zpm newpackage -f $pkgid.zpm $pkgid
                if [ $? -eq 0 ]; then
                        shift
                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
                        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 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
 
 #
 # 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
 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
 if [ $? -ne 0 ]; then
        diag h2
        cat test.out | diagstdin
index 47575e6f6361bac2fcf99df7096fe1317686534a..e61b114623c9e1007781355fae6bf8875ecf73c8 100755 (executable)
@@ -18,7 +18,7 @@ newpkg() {
                tryrun zpm newpackage -f $pkgid.zpm $pkgid
                if [ $? -eq 0 ]; then
                        shift
                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
                        return $?
                else
                        skip 1 not adding files init failed
index d97f0bea07dc3640b1d72d6cb38d4b4b04b08897..321551586adc7fc3fb1defcf41909841154275c0 100755 (executable)
@@ -18,7 +18,7 @@ newpkg() {
                tryrun zpm newpackage -f $pkgid.zpm $pkgid
                if [ $? -eq 0 ]; then
                        shift
                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
                        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
 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
 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
 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
 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
 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
 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 6cca0575c27c52d2a86e1df831806bfd326ad0f5..5fc450fd9f322b35b6d9fa400b03a637d9590fbd 100644 (file)
--- 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);
 
 /* 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);
 
 /* transactions */
 int zpm_begin(struct zpm *z);