Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Create the directories if they dont exist.
jlaffaye committed 14 years ago
commit ef53c98d970bf9338f8433df4b6a59d5a1e9bb14
parent 09e308b
4 files changed +52 -0
modified pkg/Makefile
@@ -9,6 +9,7 @@ SRCS= add.c \
		repo.c \
		update.c \
		upgrade.c \
+
		utils.c \
		version.c \
		which.c
BINDIR=		/usr/sbin
modified pkg/create.c
@@ -8,6 +8,7 @@
#include <sysexits.h>

#include "create.h"
+
#include "utils.h"

void
usage_create(void)
@@ -139,6 +140,9 @@ exec_create(int argc, char **argv)

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

	if (format == NULL) {
		fmt = TXZ;
added pkg/utils.c
@@ -0,0 +1,41 @@
+
#include <sys/param.h>
+
#include <sys/stat.h>
+

+
#include <err.h>
+
#include <errno.h>
+
#include <string.h>
+
#include <pkg.h>
+

+
#include "utils.h"
+

+
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);
+
}
added pkg/utils.h
@@ -0,0 +1,6 @@
+
#ifndef _UTILS_H
+
#define _UTILS_H
+

+
int mkdirs(const char *path);
+

+
#endif