diff options
author | 2010-09-23 18:10:16 +0000 | |
---|---|---|
committer | 2010-09-23 18:10:16 +0000 | |
commit | 0f651f4749bf71c1d642d6ce680f3749bbdbebab (patch) | |
tree | fbe2b97fb55058e3a5ed90e1c8f857ea21d55c72 | |
parent | Plug memory leak in rcs_getrev, from zinovik. (diff) | |
download | wireguard-openbsd-0f651f4749bf71c1d642d6ce680f3749bbdbebab.tar.xz wireguard-openbsd-0f651f4749bf71c1d642d6ce680f3749bbdbebab.zip |
Add cvs_mkdir() for recursive directory creation on import, based on a
diff from Michael W Bombardieri in PR 6398.
tested by & ok jasper
-rw-r--r-- | usr.bin/cvs/import.c | 8 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 43 | ||||
-rw-r--r-- | usr.bin/cvs/util.h | 3 |
3 files changed, 47 insertions, 7 deletions
diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c index 3edd9ce5b65..04b8c2f2410 100644 --- a/usr.bin/cvs/import.c +++ b/usr.bin/cvs/import.c @@ -1,4 +1,4 @@ -/* $OpenBSD: import.c,v 1.102 2010/07/23 21:46:05 ray Exp $ */ +/* $OpenBSD: import.c,v 1.103 2010/09/23 18:10:16 nicm Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -161,10 +161,8 @@ cvs_import(int argc, char **argv) import_loginfo(import_repository); - if (cvs_noexec != 1) { - if (mkdir(repo, 0755) == -1 && errno != EEXIST) - fatal("cvs_import: %s: %s", repo, strerror(errno)); - } + if (cvs_noexec != 1) + cvs_mkdir(repo, 0755); cr.enterdir = NULL; cr.leavedir = NULL; diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index f94e920c717..28f5a458029 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.152 2010/07/23 21:46:05 ray Exp $ */ +/* $OpenBSD: util.c,v 1.153 2010/09/23 18:10:16 nicm Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -682,6 +682,47 @@ cvs_mkpath(const char *path, char *tag) xfree(dir); } +void +cvs_mkdir(const char *path, mode_t mode) +{ + size_t len; + char *sp, *dp, *dir, rpath[MAXPATHLEN]; + + if (current_cvsroot->cr_method != CVS_METHOD_LOCAL || + cvs_server_active == 1) + cvs_validate_directory(path); + + dir = xstrdup(path); + + STRIP_SLASH(dir); + + if (cvs_server_active == 0) + cvs_log(LP_TRACE, "cvs_mkdir(%s)", dir); + + rpath[0] = '\0'; + + for (sp = dir; sp != NULL; sp = dp) { + dp = strchr(sp, '/'); + if (dp != NULL) + *(dp++) = '\0'; + + len = strlcat(rpath, "/", sizeof(rpath)); + if (len >= (int)sizeof(rpath)) + fatal("cvs_mkdir: overflow"); + + len = strlcat(rpath, sp, sizeof(rpath)); + if (len >= (int)sizeof(rpath)) + fatal("cvs_mkdir: overflow"); + if (1 == len) + continue; + + if (mkdir(rpath, mode) == -1 && errno != EEXIST) + fatal("cvs_mkdir: %s: %s", rpath, strerror(errno)); + } + + xfree(dir); +} + /* * Split the contents of a file into a list of lines. */ diff --git a/usr.bin/cvs/util.h b/usr.bin/cvs/util.h index d595c6b4848..e80b2ce4620 100644 --- a/usr.bin/cvs/util.h +++ b/usr.bin/cvs/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.28 2010/07/23 21:46:05 ray Exp $ */ +/* $OpenBSD: util.h,v 1.29 2010/09/23 18:10:16 nicm Exp $ */ /* * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -33,6 +33,7 @@ void cvs_modetostr(mode_t, char *, size_t); void cvs_strtomode(const char *, mode_t *); void cvs_mkadmin(const char *, const char *, const char *, char *, char *); void cvs_mkpath(const char *, char *); +void cvs_mkdir(const char *, mode_t); int cvs_cksum(const char *, char *, size_t); int cvs_getargv(const char *, char **, int); int cvs_chdir(const char *, int); |