int pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir, const char *md_dir, char *plist) { struct pkg *pkg = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; struct packing *pkg_archive = NULL; int ret = EPKG_FATAL; pkg_debug(1, "Creating package from stage directory: '%s'", rootdir); if ((ret = pkg_new(&pkg, PKG_FILE)) != EPKG_OK) goto cleanup; if ((ret = pkg_load_metadata(pkg, NULL, md_dir, plist, rootdir, false)) != EPKG_OK) goto cleanup; /* Create the archive */ pkg_archive = pkg_create_archive(outdir, pkg, format, 0); if (pkg_archive == NULL) { ret = EPKG_FATAL; /* XXX do better */ goto cleanup; } /* XXX: autoplist support doesn't work right with meta-ports */ if (0 && pkg_files(pkg, &file) != EPKG_OK && pkg_dirs(pkg, &dir) != EPKG_OK) { /* Now traverse the file directories, adding to the archive */ packing_append_tree(pkg_archive, md_dir, NULL); packing_append_tree(pkg_archive, rootdir, "/"); ret = EPKG_OK; } else { ret = pkg_create_from_dir(pkg, rootdir, pkg_archive); } cleanup: free(pkg); packing_finish(pkg_archive); return (ret); }
/* The "no concessions to old pkg_tools" variant: just get everything * from the manifest */ int pkg_create_from_manifest(const char *outdir, pkg_formats format, const char *rootdir, const char *manifest, const char *plist) { struct pkg *pkg = NULL; struct packing *pkg_archive = NULL; int ret = ENOMEM; pkg_debug(1, "Creating package from stage directory: '%s'", rootdir); if(pkg_new(&pkg, PKG_FILE) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } if ((ret = pkg_load_metadata(pkg, manifest, NULL, plist, rootdir, false)) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } /* Create the archive */ pkg_archive = pkg_create_archive(outdir, pkg, format, 0); if (pkg_archive == NULL) { ret = EPKG_FATAL; /* XXX do better */ goto cleanup; } if ((ret = pkg_create_from_dir(pkg, rootdir, pkg_archive)) != EPKG_OK) pkg_emit_error("package creation failed"); cleanup: free(pkg); packing_finish(pkg_archive); return (ret); }
int exec_register(int argc, char **argv) { struct pkg *pkg = NULL; struct pkgdb *db = NULL; const char *plist = NULL; const char *mdir = NULL; const char *mfile = NULL; const char *input_path = NULL; const char *location = NULL; bool legacy = false; bool testing_mode = false; int ch; int ret = EPKG_OK; int retcode = EX_OK; /* options descriptor */ struct option longopts[] = { { "automatic", no_argument, NULL, 'A' }, { "debug", no_argument, NULL, 'd' }, { "legacy", no_argument, NULL, 'l' }, { "manifest", required_argument, NULL, 'M' }, { "metadata", required_argument, NULL, 'm' }, { "plist", required_argument, NULL, 'f' }, { "relocate", required_argument, NULL, 1 }, { "root", required_argument, NULL, 'i' }, { "test", no_argument, NULL, 't' }, { NULL, 0, NULL, 0}, }; if (pkg_new(&pkg, PKG_INSTALLED) != EPKG_OK) err(EX_OSERR, "malloc"); while ((ch = getopt_long(argc, argv, "+Adf:i:lM:m:t", longopts, NULL)) != -1) { switch (ch) { case 'A': case 'd': pkg_set(pkg, PKG_AUTOMATIC, (bool)true); break; case 'f': plist = optarg; break; case 'i': input_path = optarg; break; case 'l': legacy = true; break; case 'M': mfile = optarg; break; case 'm': mdir = optarg; break; case 't': testing_mode = true; break; case 1: location = optarg; break; default: warnx("Unrecognised option -%c\n", ch); usage_register(); pkg_free(pkg); return (EX_USAGE); } } retcode = pkgdb_access(PKGDB_MODE_READ | PKGDB_MODE_WRITE | PKGDB_MODE_CREATE, PKGDB_DB_LOCAL); if (retcode == EPKG_ENOACCESS) { warnx("Insufficient privileges to register packages"); pkg_free(pkg); return (EX_NOPERM); } else if (retcode != EPKG_OK) { pkg_free(pkg); return (EX_IOERR); } else retcode = EX_OK; /* * Ideally, the +MANIFEST should be all that is necessary, * since it can contain all of the meta-data supplied by the * other files mentioned below. These are here for backwards * compatibility with the way the ports tree works with * pkg_tools. * * The -M option specifies one manifest file to read the * meta-data from, and overrides the use of legacy meta-data * inputs. * * Dependencies, shlibs, files etc. may be derived by * analysing the package files (maybe discovered as the * content of the staging directory) unless -t (testing_mode) * is used. */ if (mfile != NULL && mdir != NULL) { warnx("Cannot use both -m and -M together"); usage_register(); pkg_free(pkg); return (EX_USAGE); } if (mfile == NULL && mdir == NULL) { warnx("One of either -m or -M flags is required"); usage_register(); pkg_free(pkg); return (EX_USAGE); } if (testing_mode && input_path != NULL) { warnx("-i incompatible with -t option"); usage_register(); pkg_free(pkg); return (EX_USAGE); } ret = pkg_load_metadata(pkg, mfile, mdir, plist, input_path, testing_mode); if (ret != EPKG_OK) { pkg_free(pkg); return (EX_IOERR); } if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) { pkg_free(pkg); return (EX_IOERR); } if (pkgdb_obtain_lock(db, PKGDB_LOCK_EXCLUSIVE) != EPKG_OK) { pkgdb_close(db); pkg_free(pkg); warnx("Cannot get an exclusive lock on a database, it is locked by another process"); return (EX_TEMPFAIL); } retcode = pkg_add_port(db, pkg, input_path, location, testing_mode); if (!legacy && retcode == EPKG_OK && messages != NULL) { printf("%s\n", utstring_body(messages)); } pkg_free(pkg); return (retcode != EPKG_OK ? EX_SOFTWARE : EX_OK); }