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))
--- /dev/null
+.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)
zpm->error = rv;
return 0;
}
+ sqlite3_free(sql);
return st;
}
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;
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];
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;
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 '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;
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) {
}
#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;
PF=test.db
-plan 32
+plan 34
require rm -rf tmp
require mkdir tmp
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)
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)
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"
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
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
#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
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
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
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
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 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 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
/* 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);