pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/pkg_install-renovation]: pkgsrc/pkgtools/pkg_install/files Internal i...
details: https://anonhg.NetBSD.org/pkgsrc/rev/f0fb7247d021
branches: pkg_install-renovation
changeset: 541572:f0fb7247d021
user: joerg <joerg%pkgsrc.org@localhost>
date: Wed Jul 30 15:02:18 2008 +0000
description:
Internal implementation of mkdir_p.
diffstat:
pkgtools/pkg_install/files/add/perform.c | 53 ++++++++++++++++++++++++++++++-
pkgtools/pkg_install/files/lib/lib.h | 4 +-
2 files changed, 51 insertions(+), 6 deletions(-)
diffs (92 lines):
diff -r 071d46e3cdbb -r f0fb7247d021 pkgtools/pkg_install/files/add/perform.c
--- a/pkgtools/pkg_install/files/add/perform.c Sun Jul 27 22:37:34 2008 +0000
+++ b/pkgtools/pkg_install/files/add/perform.c Wed Jul 30 15:02:18 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.70.4.10 2008/06/27 15:25:52 joerg Exp $ */
+/* $NetBSD: perform.c,v 1.70.4.11 2008/07/30 15:02:18 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
@@ -6,7 +6,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
-__RCSID("$NetBSD: perform.c,v 1.70.4.10 2008/06/27 15:25:52 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.70.4.11 2008/07/30 15:02:18 joerg Exp $");
/*-
* Copyright (c) 2003 Grant Beattie <grant%NetBSD.org@localhost>
@@ -123,7 +123,54 @@
static int
mkdir_p(const char *path)
{
- return fexec(MKDIR_CMD, "-p", path, (void *)NULL);
+ char *p, *cur_end;
+ int done;
+
+ /*
+ * Handle the easy case of direct success or
+ * pre-existing directory first.
+ */
+ if (mkdir(path, 0777) == 0 || errno == EEXIST)
+ return 0;
+ if (errno != ENOENT)
+ return -1;
+
+ if ((p = strdup(path)) == NULL)
+ err(EXIT_FAILURE, "strdup failed");
+
+ cur_end = p;
+
+ for (;;) {
+ /*
+ * First skip leading slashes either from / or
+ * from the last iteration.
+ */
+ cur_end += strspn(cur_end, "/");
+ /* Find end of actual directory name. */
+ cur_end += strcspn(cur_end, "/");
+
+ /*
+ * Remember if this is the last component and
+ * overwrite / if needed.
+ */
+ done = (*cur_end == '\0');
+ *cur_end = '\0';
+
+ /*
+ * ENOENT can only happen if something else races us,
+ * in which case we should better give up.
+ */
+ if (mkdir(p, 0777) == -1 && errno != EEXIST) {
+ free(p);
+ return -1;
+ }
+ if (done)
+ break;
+ *cur_end = '/';
+ }
+
+ free(p);
+ return 0;
}
/*
diff -r 071d46e3cdbb -r f0fb7247d021 pkgtools/pkg_install/files/lib/lib.h
--- a/pkgtools/pkg_install/files/lib/lib.h Sun Jul 27 22:37:34 2008 +0000
+++ b/pkgtools/pkg_install/files/lib/lib.h Wed Jul 30 15:02:18 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.42.2.7 2008/07/05 17:26:39 joerg Exp $ */
+/* $NetBSD: lib.h,v 1.42.2.8 2008/07/30 15:02:18 joerg Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@@ -86,8 +86,6 @@
#define DEF_UMASK 022
#endif
-#define MKDIR_CMD "mkdir"
-
/* Usually "rm", but often "echo" during debugging! */
#define REMOVE_CMD "rm"
Home |
Main Index |
Thread Index |
Old Index