diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2005-05-24 20:04:44 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2005-05-24 20:04:44 +0000 |
commit | 0f7c34393ce93bad18649e843389dcd918e2303b (patch) | |
tree | 3e77c8982af7d2bbae1c1dbd3e1fbc4a63ae5c6d | |
parent | 3c07aef93dcbaa855eaba9b2490367a4e84164b2 (diff) |
- simplify cvs_mkadmin().
- create the correct base paths in checkout.
- remove the CVS_CMD_SENDARGS2 flag for checkout, it doesn't need it.
okay jfb@
-rw-r--r-- | usr.bin/cvs/checkout.c | 24 | ||||
-rw-r--r-- | usr.bin/cvs/cvs.h | 4 | ||||
-rw-r--r-- | usr.bin/cvs/file.c | 7 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 38 |
4 files changed, 36 insertions, 37 deletions
diff --git a/usr.bin/cvs/checkout.c b/usr.bin/cvs/checkout.c index d7849a163fc..073f70e6c8a 100644 --- a/usr.bin/cvs/checkout.c +++ b/usr.bin/cvs/checkout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: checkout.c,v 1.22 2005/05/24 04:12:25 jfb Exp $ */ +/* $OpenBSD: checkout.c,v 1.23 2005/05/24 20:04:43 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -25,6 +25,7 @@ */ #include <sys/types.h> +#include <sys/stat.h> #include <errno.h> #include <stdio.h> @@ -59,7 +60,7 @@ struct cvs_cmd cvs_cmd_checkout = { NULL, NULL, NULL, - CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR | CVS_CMD_SENDARGS2 + CVS_CMD_ALLOWSPEC | CVS_CMD_SENDDIR }; static char *date, *rev, *koptstr, *tgtdir, *rcsid; @@ -152,11 +153,26 @@ static int cvs_checkout_pre_exec(struct cvsroot *root) { int i; + char *sp; - /* create any required base directories */ for (i = 0; i < co_nmod; i++) { - if (cvs_file_create(NULL, co_mods[i], DT_DIR, 0755) < 0) + if ((sp = strchr(co_mods[i], '/')) != NULL) + *sp = '\0'; + + if ((mkdir(co_mods[i], 0755) == -1) && (errno != EEXIST)) { + cvs_log(LP_ERRNO, "can't create base directory '%s'", + co_mods[i]); + return (CVS_EX_DATA); + } + + if (cvs_mkadmin(co_mods[i], root->cr_str, co_mods[i]) < 0) { + cvs_log(LP_ERROR, "can't create base directory '%s'", + co_mods[i]); return (CVS_EX_DATA); + } + + if (sp != NULL) + *sp = '/'; } if (root->cr_method != CVS_METHOD_LOCAL) { diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h index c4418b7941f..d16e167a4f7 100644 --- a/usr.bin/cvs/cvs.h +++ b/usr.bin/cvs/cvs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.h,v 1.58 2005/05/24 04:12:25 jfb Exp $ */ +/* $OpenBSD: cvs.h,v 1.59 2005/05/24 20:04:43 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -389,7 +389,7 @@ int cvs_readrepo (const char *, char *, size_t); int cvs_modetostr (mode_t, char *, size_t); int cvs_strtomode (const char *, mode_t *); int cvs_splitpath (const char *, char *, size_t, char **); -int cvs_mkadmin (CVSFILE *, mode_t); +int cvs_mkadmin (const char *, const char *, const char *); int cvs_cksum (const char *, char *, size_t); int cvs_exec (int, char **, int []); int cvs_getargv (const char *, char **, int); diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c index ae5d78294dd..f109e3fb599 100644 --- a/usr.bin/cvs/file.c +++ b/usr.bin/cvs/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.77 2005/05/24 04:12:25 jfb Exp $ */ +/* $OpenBSD: file.c,v 1.78 2005/05/24 20:04:43 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -269,7 +269,8 @@ cvs_file_create(CVSFILE *parent, const char *path, u_int type, mode_t mode) return (NULL); } - if ((mkdir(path, mode) == -1) || (cvs_mkadmin(cfp, mode) < 0)) { + if ((mkdir(path, mode) == -1) || + (cvs_mkadmin(path, cfp->cf_root->cr_str, cfp->cf_repo) < 0)) { cvs_file_free(cfp); return (NULL); } @@ -574,7 +575,7 @@ cvs_load_dirinfo(CVSFILE *cf, int flags) return (-1); if (flags & CF_MKADMIN) - cvs_mkadmin(cf, 0755); + cvs_mkadmin(fpath, cf->cf_root->cr_str, NULL); /* if the CVS administrative directory exists, load the info */ l = snprintf(pbuf, sizeof(pbuf), "%s/" CVS_PATH_CVSDIR, fpath); diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 4005bc26c62..12ea00ad898 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.27 2005/05/20 10:40:22 pat Exp $ */ +/* $OpenBSD: util.c,v 1.28 2005/05/24 20:04:43 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -422,16 +422,13 @@ cvs_freeargv(char **argv, int argc) * Returns 0 on success, or -1 on failure. */ int -cvs_mkadmin(CVSFILE *cdir, mode_t mode) +cvs_mkadmin(const char *dpath, const char *rootpath, const char *repopath) { int l; - char dpath[MAXPATHLEN], path[MAXPATHLEN]; + char path[MAXPATHLEN]; FILE *fp; CVSENTRIES *ef; struct stat st; - struct cvsroot *root; - - cvs_file_getpath(cdir, dpath, sizeof(dpath)); l = snprintf(path, sizeof(path), "%s/" CVS_PATH_CVSDIR, dpath); if (l == -1 || l >= (int)sizeof(path)) { @@ -440,7 +437,7 @@ cvs_mkadmin(CVSFILE *cdir, mode_t mode) return (-1); } - if ((mkdir(path, mode) == -1) && (errno != EEXIST)) { + if ((mkdir(path, 0755) == -1) && (errno != EEXIST)) { cvs_log(LP_ERRNO, "failed to create directory %s", path); return (-1); } @@ -449,7 +446,6 @@ cvs_mkadmin(CVSFILE *cdir, mode_t mode) ef = cvs_ent_open(dpath, O_WRONLY); (void)cvs_ent_close(ef); - root = cdir->cf_root; l = snprintf(path, sizeof(path), "%s/" CVS_PATH_ROOTSPEC, dpath); if (l == -1 || l >= (int)sizeof(path)) { errno = ENAMETOOLONG; @@ -457,28 +453,14 @@ cvs_mkadmin(CVSFILE *cdir, mode_t mode) return (-1); } - if ((root != NULL) && (stat(path, &st) != 0) && (errno == ENOENT)) { + if ((stat(path, &st) != 0) && (errno == ENOENT)) { fp = fopen(path, "w"); if (fp == NULL) { cvs_log(LP_ERRNO, "failed to open %s", path); return (-1); } - if (root->cr_user != NULL) { - fprintf(fp, "%s", root->cr_user); - if (root->cr_pass != NULL) - fprintf(fp, ":%s", root->cr_pass); - if (root->cr_host != NULL) - putc('@', fp); - } - - if (root->cr_host != NULL) { - fprintf(fp, "%s", root->cr_host); - if (root->cr_dir != NULL) - putc(':', fp); - } - if (root->cr_dir) - fprintf(fp, "%s", root->cr_dir); - putc('\n', fp); + if (rootpath != NULL) + fprintf(fp, "%s\n", rootpath); (void)fclose(fp); } @@ -489,14 +471,14 @@ cvs_mkadmin(CVSFILE *cdir, mode_t mode) return (-1); } - if ((stat(path, &st) != 0) && (errno == ENOENT) && - (cdir->cf_repo != NULL)) { + if ((stat(path, &st) != 0) && (errno == ENOENT)) { fp = fopen(path, "w"); if (fp == NULL) { cvs_log(LP_ERRNO, "failed to open %s", path); return (-1); } - fprintf(fp, "%s\n", cdir->cf_repo); + if (repopath != NULL) + fprintf(fp, "%s\n", repopath); (void)fclose(fp); } |