version 1.20, 2006/01/02 08:11:56 |
version 1.21, 2006/01/08 18:02:06 |
|
|
}; |
}; |
|
|
static int cvs_init_pre_exec(struct cvsroot *); |
static int cvs_init_pre_exec(struct cvsroot *); |
static int cvs_init_create_files(struct cvsroot *); |
static void cvs_init_create_files(struct cvsroot *); |
|
|
struct cvs_cmd cvs_cmd_init = { |
struct cvs_cmd cvs_cmd_init = { |
CVS_OP_INIT, CVS_REQ_INIT, "init", |
CVS_OP_INIT, CVS_REQ_INIT, "init", |
|
|
static int |
static int |
cvs_init_pre_exec(struct cvsroot *root) |
cvs_init_pre_exec(struct cvsroot *root) |
{ |
{ |
if (root->cr_method == CVS_METHOD_LOCAL) { |
if (root->cr_method == CVS_METHOD_LOCAL) |
if (cvs_init_create_files(root) < 0) |
cvs_init_create_files(root); |
return (CVS_EX_FILE); |
|
} |
|
|
|
return (0); |
return (0); |
} |
} |
|
|
* Returns 0 on success, -1 on failure. |
* Returns 0 on success, -1 on failure. |
* |
* |
*/ |
*/ |
static int |
static void |
cvs_init_create_files(struct cvsroot *root) |
cvs_init_create_files(struct cvsroot *root) |
{ |
{ |
size_t len; |
size_t len; |
|
|
if (mkdir(root->cr_dir, 0777) == -1) { |
if (mkdir(root->cr_dir, 0777) == -1) { |
if (!(errno == EEXIST || (errno == EACCES && |
if (!(errno == EEXIST || (errno == EACCES && |
(stat(root->cr_dir, &st) == 0) && S_ISDIR(st.st_mode)))) { |
(stat(root->cr_dir, &st) == 0) && S_ISDIR(st.st_mode)))) { |
cvs_log(LP_ERRNO, "cannot make directory %s", |
fatal("cvs_init_create_files: mkdir: %s: %s", |
root->cr_dir); |
root->cr_dir, strerror(errno)); |
return (CVS_EX_FILE); |
|
} |
} |
} |
} |
|
|
|
|
len = cvs_path_cat(root->cr_dir, cvsroot_files[i].cf_path, |
len = cvs_path_cat(root->cr_dir, cvsroot_files[i].cf_path, |
path, sizeof(path)); |
path, sizeof(path)); |
if (len >= sizeof(path)) |
if (len >= sizeof(path)) |
return (-1); |
fatal("cvs_init_create_files: path truncation"); |
|
|
if (cvsroot_files[i].cf_type == CFT_DIR) { |
if (cvsroot_files[i].cf_type == CFT_DIR) { |
if (mkdir(path, cvsroot_files[i].cf_mode) == -1) { |
if (mkdir(path, cvsroot_files[i].cf_mode) == -1) { |
if (!(errno == EEXIST || (errno == EACCES && |
if (!(errno == EEXIST || (errno == EACCES && |
(stat(path, &st) == 0) && |
(stat(path, &st) == 0) && |
S_ISDIR(st.st_mode)))) { |
S_ISDIR(st.st_mode)))) { |
cvs_log(LP_ERRNO, |
fatal("cvs_init_create_files: mkdir: " |
"cannot make directory %s", path); |
"%s: %s", path, strerror(errno)); |
return (CVS_EX_FILE); |
|
} |
} |
} |
} |
} else if (cvsroot_files[i].cf_type == CFT_FILE) { |
} else if (cvsroot_files[i].cf_type == CFT_FILE) { |
fd = open(path, O_WRONLY|O_CREAT|O_EXCL, |
fd = open(path, O_WRONLY|O_CREAT|O_EXCL, |
cvsroot_files[i].cf_mode); |
cvsroot_files[i].cf_mode); |
if (fd == -1) { |
if (fd == -1) |
cvs_log(LP_ERRNO, "failed to create `%s'", |
fatal("cvs_init_create_file: open failed: %s", |
path); |
strerror(errno)); |
return (CVS_EX_FILE); |
|
} |
|
|
|
(void)close(fd); |
(void)close(fd); |
|
|
strlcat(path, RCS_FILE_EXT, sizeof(path)); |
strlcat(path, RCS_FILE_EXT, sizeof(path)); |
rfp = rcs_open(path, RCS_WRITE|RCS_CREATE, 0640); |
rfp = rcs_open(path, RCS_WRITE|RCS_CREATE, 0640); |
if (rfp == NULL) { |
if (rfp == NULL) |
return (CVS_EX_DATA); |
return; |
} |
|
|
|
rcs_close(rfp); |
rcs_close(rfp); |
} |
} |
} |
} |
|
|
return (0); |
|
} |
} |