Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Make dirs inside pkg_create().
jlaffaye committed 14 years ago
commit 112c51896d1030d57a5c7476df7d0baa5fb28688
parent e44d566
5 files changed +13 -45
modified libpkg/packing.c
@@ -27,6 +27,8 @@ packing_init(struct packing **pack, const char *path, pkg_formats format)
	char archive_path[MAXPATHLEN];
	const char *ext;

+
	assert(pack != NULL);
+

	if ((*pack = calloc(1, sizeof(struct packing))) == NULL) {
		EMIT_ERRNO("malloc", "");
		return (EPKG_FATAL);
@@ -45,6 +47,7 @@ packing_init(struct packing **pack, const char *path, pkg_formats format)
			archive_read_finish((*pack)->aread);
			archive_write_finish((*pack)->awrite);
			archive_entry_free((*pack)->entry);
+
			*pack = NULL;
			return EPKG_FATAL; /* error set by _set_format() */
		}
		snprintf(archive_path, sizeof(archive_path), "%s.%s", path, ext);
modified libpkg/pkg_create.c
@@ -82,22 +82,22 @@ pkg_create_archive(const char *outdir, struct pkg *pkg, pkg_formats format, int
	/*
	 * Ensure that we have all the information we need
	 */
-
	if ((pkg->flags & required_flags) != required_flags) {
-
		printf("error: required flags not set\n");
+
	assert((pkg->flags & required_flags) == required_flags);
+

+
	if (mkdirs(outdir) != EPKG_OK)
		return NULL;
-
	}

	if (asprintf(&pkg_path, "%s/%s-%s", outdir, pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION)) == -1) {
-
		perror("asprintf");
-
		return NULL; /* XXX do better */
-
	}
-
	if (packing_init(&pkg_archive, pkg_path, format) != EPKG_OK) {
-
		perror("packing_init");
-
		return NULL;
+
		EMIT_ERRNO("asprintf", "");
+
		return (NULL);
	}

+
	if (packing_init(&pkg_archive, pkg_path, format) != EPKG_OK)
+
		pkg_archive = NULL;
+

	if (pkg_path != NULL)
		free(pkg_path);
+

	return pkg_archive;
}

modified libpkg/pkg_util.c
@@ -58,7 +58,7 @@ sbuf_free(struct sbuf *buf)
int
mkdirs(const char *_path)
{
-
	char path[MAXPATHLEN];
+
	char path[MAXPATHLEN + 1];
	char *p;

	strlcpy(path, _path, sizeof(path));
modified pkg/create.c
@@ -132,9 +132,6 @@ exec_create(int argc, char **argv)

	if (outdir == NULL)
		outdir = "./";
-
	else
-
		if (mkdirs(outdir) != EPKG_OK)
-
			return (EX_SOFTWARE);

	if (format == NULL) {
		fmt = TXZ;
modified pkg/utils.c
@@ -26,35 +26,3 @@ query_yesno(const char *msg)

        return r;
}
-

-
int
-
mkdirs(const char *_path)
-
{
-
	char path[MAXPATHLEN];
-
	char *p;
-

-
	strlcpy(path, _path, sizeof(path));
-
	p = path;
-
	if (*p == '/')
-
		p++;
-

-
	for (;;) {
-
		if ((p = strchr(p, '/')) != NULL)
-
			*p = '\0';
-

-
		if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
-
			if (errno != EEXIST && errno != EISDIR) {
-
				warn("mkdir(%s)", path);
-
				return (EPKG_FATAL);
-
			}
-

-
		/* that was the last element of the path */
-
		if (p == NULL)
-
			break;
-

-
		*p = '/';
-
		p++;
-
	}
-

-
	return (EPKG_OK);
-
}