diff options
author | Xavier Santolaria <xsa@cvs.openbsd.org> | 2005-12-24 19:07:53 +0000 |
---|---|---|
committer | Xavier Santolaria <xsa@cvs.openbsd.org> | 2005-12-24 19:07:53 +0000 |
commit | 2b13d70f1a07f04c738b10a08c370ae26e34563e (patch) | |
tree | 78a7826d60f3195ceca44305d9a00a5e647f5f38 /usr.bin/cvs | |
parent | 2a5186542c0004c0dc3aecc03c9fca5308018e01 (diff) |
add an argument to cvs_chdir() which enables or not the removal
of the directory we just chdir'd to.
Useful when the function fails especially for the server mode and
its temporary directory. This way it's not left behind on exit.
ok joris@.
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r-- | usr.bin/cvs/cvs.h | 4 | ||||
-rw-r--r-- | usr.bin/cvs/release.c | 10 | ||||
-rw-r--r-- | usr.bin/cvs/req.c | 6 | ||||
-rw-r--r-- | usr.bin/cvs/server.c | 7 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 16 |
5 files changed, 22 insertions, 21 deletions
diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h index 23d09e60f0b..1a1c128e0fe 100644 --- a/usr.bin/cvs/cvs.h +++ b/usr.bin/cvs/cvs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.h,v 1.92 2005/12/19 18:21:30 xsa Exp $ */ +/* $OpenBSD: cvs.h,v 1.93 2005/12/24 19:07:52 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -437,7 +437,7 @@ int cvs_mkadmin(const char *, const char *, const char *, char *, int cvs_cksum(const char *, char *, size_t); int cvs_exec(int, char **, int []); int cvs_getargv(const char *, char **, int); -int cvs_chdir(const char *); +int cvs_chdir(const char *, int); int cvs_rename(const char *, const char *); int cvs_unlink(const char *); int cvs_rmdir(const char *); diff --git a/usr.bin/cvs/release.c b/usr.bin/cvs/release.c index 73418748c1b..9c419ba3d1a 100644 --- a/usr.bin/cvs/release.c +++ b/usr.bin/cvs/release.c @@ -1,4 +1,4 @@ -/* $OpenBSD: release.c,v 1.24 2005/12/22 14:31:44 xsa Exp $ */ +/* $OpenBSD: release.c,v 1.25 2005/12/24 19:07:52 xsa Exp $ */ /* * Copyright (c) 2005 Xavier Santolaria <xsa@openbsd.org> * All rights reserved. @@ -161,7 +161,7 @@ cvs_release_dir(CVSFILE *cf, void *arg) return (0); /* chdir before running the `cvs update' command */ - cvs_chdir(dpath); + cvs_chdir(dpath, 0); /* test if dir has CVS/ directory */ if (stat(CVS_PATH_CVSDIR, &st) == -1) { @@ -199,7 +199,7 @@ cvs_release_dir(CVSFILE *cf, void *arg) cvs_log(LP_ERR, "unable to release `%s'", dpath); /* change back to original working dir */ - cvs_chdir(wdir); + cvs_chdir(wdir, 0); } printf("You have [%d] altered file%s in this repository.\n", @@ -218,13 +218,13 @@ cvs_release_dir(CVSFILE *cf, void *arg) "** `%s' aborted by user choice.\n", cvs_command); /* change back to original working dir */ - cvs_chdir(wdir); + cvs_chdir(wdir, 0); return (-1); } /* change back to original working dir */ - cvs_chdir(wdir); + cvs_chdir(wdir, 0); if (dflag == 1) { if (cvs_rmdir(dpath) != 0) diff --git a/usr.bin/cvs/req.c b/usr.bin/cvs/req.c index 35baf600d76..ea9237959c3 100644 --- a/usr.bin/cvs/req.c +++ b/usr.bin/cvs/req.c @@ -1,4 +1,4 @@ -/* $OpenBSD: req.c,v 1.37 2005/12/22 14:31:44 xsa Exp $ */ +/* $OpenBSD: req.c,v 1.38 2005/12/24 19:07:52 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -282,7 +282,7 @@ cvs_req_directory(int reqid, char *line) * Lets make sure we always start at the correct * directory. */ - cvs_chdir(cvs_server_tmpdir); + cvs_chdir(cvs_server_tmpdir, 1); /* * Set repository path. @@ -609,7 +609,7 @@ cvs_req_command(int reqid, char *line) /* switch to the correct directory */ if (cmdp->cmd_op != CVS_OP_VERSION) - cvs_chdir(cvs_server_tmpdir); + cvs_chdir(cvs_server_tmpdir, 1); ret = cvs_startcmd(cmdp, cvs_req_nargs, cvs_req_args); diff --git a/usr.bin/cvs/server.c b/usr.bin/cvs/server.c index 60f82d9d83d..e5b29854f2a 100644 --- a/usr.bin/cvs/server.c +++ b/usr.bin/cvs/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.25 2005/12/20 16:55:21 xsa Exp $ */ +/* $OpenBSD: server.c,v 1.26 2005/12/24 19:07:52 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -96,10 +96,7 @@ cvs_server(int argc, char **argv) fatal("cvs_server: mkdir: `%s': %s", cvs_server_tmpdir, strerror(errno)); - if (cvs_chdir(cvs_server_tmpdir) == -1) { - (void)cvs_rmdir(cvs_server_tmpdir); - fatal("cvs_server: cvs_chdir failed"); - } + cvs_chdir(cvs_server_tmpdir, 1); for (;;) { if (fgets(reqbuf, (int)sizeof(reqbuf), stdin) == NULL) { diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 11565ea828f..c912c7cc58d 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.62 2005/12/24 04:10:51 joris Exp $ */ +/* $OpenBSD: util.c,v 1.63 2005/12/24 19:07:52 xsa Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -495,15 +495,19 @@ cvs_exec(int argc, char **argv, int fds[3]) /* * cvs_chdir() * - * Change to directory. - * chdir() wrapper with an error message. + * Change to directory <path>. + * If <rm> is equal to `1', <path> is removed if chdir() fails so we + * do not have temporary directories leftovers. * Returns 0 on success. */ int -cvs_chdir(const char *path) +cvs_chdir(const char *path, int rm) { - if (chdir(path) == -1) + if (chdir(path) == -1) { + if (rm == 1) + cvs_unlink(path); fatal("cvs_chdir: `%s': %s", path, strerror(errno)); + } return (0); } @@ -698,7 +702,7 @@ cvs_create_dir(const char *path, int create_adm, char *root, char *repo) } /* All went ok, switch to the newly created directory. */ - cvs_chdir(d); + cvs_chdir(d, 0); d = strtok(NULL, "/"); } |