Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Create the dirs in cachedir (Fixes issue #24).
jlaffaye committed 14 years ago
commit dc7ed921ead10cc5bbb091f2fde37ffdc0f070ac
parent ef6da07
3 files changed +44 -0
modified libpkg/pkg_repo.c
@@ -1,3 +1,5 @@
+
#include <errno.h>
+
#include <libgen.h>
#include <string.h>
#include <unistd.h>

@@ -10,6 +12,7 @@ pkg_repo_fetch(struct pkg *pkg, void *data, fetch_cb cb)
{
	char dest[MAXPATHLEN];
	char cksum[65];
+
	char *path;
	char *url;
	int retcode = EPKG_OK;

@@ -24,6 +27,14 @@ pkg_repo_fetch(struct pkg *pkg, void *data, fetch_cb cb)
	if (access(dest, F_OK) == 0)
		goto checksum;

+
	/* Create the dirs in cachedir */
+
	if ((path = dirname(dest)) == NULL) {
+
		retcode = pkg_error_set(EPKG_FATAL, "dirname(%s): %s", dest, strerror(errno));
+
		goto cleanup;
+
	}
+
	if ((retcode = mkdirs(path)) != 0)
+
		goto cleanup;
+

	asprintf(&url, "%s/%s", pkg_config("PACKAGESITE"),
			 pkg_get(pkg, PKG_REPOPATH));

modified libpkg/pkg_util.c
@@ -58,6 +58,38 @@ sbuf_free(struct sbuf *buf)
}

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) {
+
				pkg_error_set(EPKG_FATAL, "mkdir(%s): %s", path, strerror(errno));
+
				return (EPKG_FATAL);
+
			}
+

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

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

+
	return (EPKG_OK);
+
}
+

+
int
file_to_buffer(const char *path, char **buffer, off_t *sz)
{
	int fd;
modified libpkg/pkg_util.h
@@ -20,6 +20,7 @@ const char * sbuf_get(struct sbuf *);
void sbuf_reset(struct sbuf *);
void sbuf_free(struct sbuf *);

+
int mkdirs(const char *path);
int file_to_buffer(const char *, char **, off_t *);
int format_exec_cmd(char **, const char *, const char *, const char *);
int split_chr(char *, char);