diff options
author | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2008-01-10 09:44:33 +0000 |
---|---|---|
committer | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2008-01-10 09:44:33 +0000 |
commit | 00d9004b3b51d6c5d288c304e925ac19862fbf9e (patch) | |
tree | 6c04ed557721eb469ccc874b5181f4ec0556edf6 /usr.bin | |
parent | be9d6014c8bb0a19cc66ad4291244d4580f8b231 (diff) |
Handle the addition of directories right, especially in remote setups with
GNU cvs as a server.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/add.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/usr.bin/cvs/add.c b/usr.bin/cvs/add.c index 5deb16536aa..06d322d3b1f 100644 --- a/usr.bin/cvs/add.c +++ b/usr.bin/cvs/add.c @@ -1,4 +1,4 @@ -/* $OpenBSD: add.c,v 1.84 2008/01/10 09:41:52 tobias Exp $ */ +/* $OpenBSD: add.c,v 1.85 2008/01/10 09:44:32 tobias Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org> @@ -29,6 +29,7 @@ extern char *__progname; void cvs_add_local(struct cvs_file *); void cvs_add_entry(struct cvs_file *); +void cvs_add_remote(struct cvs_file *); static void add_directory(struct cvs_file *); static void add_file(struct cvs_file *); @@ -89,7 +90,7 @@ cvs_add(int argc, char **argv) if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) { cvs_client_connect_to_server(); - cr.fileproc = cvs_client_sendfile; + cr.fileproc = cvs_add_remote; if (kflag != RCS_KWEXP_DEFAULT) cvs_client_send_request("Argument %s", kbuf); @@ -105,8 +106,8 @@ cvs_add(int argc, char **argv) cvs_file_run(argc, argv, &cr); if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) { - cvs_client_send_files(argv, argc); cvs_client_senddir("."); + cvs_client_send_files(argv, argc); cvs_client_send_request("add"); cvs_client_get_responses(); @@ -161,6 +162,30 @@ cvs_add_local(struct cvs_file *cf) add_file(cf); } +void +cvs_add_remote(struct cvs_file *cf) +{ + char path[MAXPATHLEN]; + + cvs_log(LP_TRACE, "cvs_add_remote(%s)", cf->file_path); + + cvs_file_classify(cf, cvs_directory_tag); + + if (cf->file_type == CVS_DIR) { + cvs_get_repository_path(cf->file_wd, path, MAXPATHLEN); + if (strlcat(path, "/", sizeof(path)) >= sizeof(path)) + fatal("cvs_add_remote: truncation"); + if (strlcat(path, cf->file_path, sizeof(path)) >= sizeof(path)) + fatal("cvs_add_remote: truncation"); + cvs_client_send_request("Directory %s\n%s", cf->file_path, + path); + + add_directory(cf); + } else { + cvs_client_sendfile(cf); + } +} + static void add_directory(struct cvs_file *cf) { @@ -187,7 +212,12 @@ add_directory(struct cvs_file *cf) (void)xsnprintf(entry, MAXPATHLEN, "%s/%s", cf->file_path, CVS_PATH_CVSDIR); - if (stat(entry, &st) != -1) { + if (cvs_server_active) { + if (mkdir(cf->file_rpath, 0755) == -1 && + errno != EEXIST) + fatal("add_directory: %s: %s", cf->file_rpath, + strerror(errno)); + } else if (stat(entry, &st) != -1) { if (!S_ISDIR(st.st_mode)) { cvs_log(LP_ERR, "%s exists but is not " "directory", entry); @@ -199,7 +229,7 @@ add_directory(struct cvs_file *cf) } else if (cvs_noexec != 1) { if (mkdir(cf->file_rpath, 0755) == -1 && errno != EEXIST) - fatal("add_directory: %s: %s", cf->file_path, + fatal("add_directory: %s: %s", cf->file_rpath, strerror(errno)); cvs_get_repository_name(cf->file_wd, repo, @@ -221,7 +251,7 @@ add_directory(struct cvs_file *cf) } } - if (added == 1) { + if (added == 1 && current_cvsroot->cr_method == CVS_METHOD_LOCAL) { (void)xsnprintf(msg, sizeof(msg), "Directory %s added to the repository", cf->file_rpath); |