version 1.72, 2005/09/30 14:50:32 |
version 1.73, 2005/09/30 15:06:46 |
|
|
fputs("@\n\n", fp); |
fputs("@\n\n", fp); |
} |
} |
fclose(fp); |
fclose(fp); |
|
|
/* |
/* |
* We try to use rename() to atomically put the new file in place. |
* We try to use rename() to atomically put the new file in place. |
* If that fails, we try a copy. |
* If that fails, we try a copy. |
|
|
rfp->rf_path); |
rfp->rf_path); |
return (-1); |
return (-1); |
} |
} |
|
|
if ((from_fd = open(fn, O_RDONLY)) == -1) { |
if ((from_fd = open(fn, O_RDONLY)) == -1) { |
cvs_log(LP_ERRNO, "failed to open `%s'", |
cvs_log(LP_ERRNO, "failed to open `%s'", |
rfp->rf_path); |
rfp->rf_path); |
return (-1); |
return (-1); |
} |
} |
|
|
if ((to_fd = open(rfp->rf_path, O_WRONLY|O_CREAT)) |
if ((to_fd = open(rfp->rf_path, O_WRONLY|O_CREAT)) |
== -1) { |
== -1) { |
cvs_log(LP_ERRNO, "failed to open `%s'", |
cvs_log(LP_ERRNO, "failed to open `%s'", fn); |
fn); |
|
close(from_fd); |
close(from_fd); |
return (-1); |
return (-1); |
} |
} |
|
|
if ((bp = malloc(MAXBSIZE)) == NULL) { |
if ((bp = malloc(MAXBSIZE)) == NULL) { |
cvs_log(LP_ERRNO, |
cvs_log(LP_ERRNO, "failed to allocate memory"); |
"failed to allocate memory"); |
|
close(from_fd); |
close(from_fd); |
close(to_fd); |
close(to_fd); |
return (-1); |
return (-1); |
} |
} |
|
|
while ((nread = read(from_fd, bp, MAXBSIZE)) > 0) { |
while ((nread = read(from_fd, bp, MAXBSIZE)) > 0) { |
if (write(to_fd, bp, nread) != nread) |
if (write(to_fd, bp, nread) != nread) |
goto err; |
goto err; |
} |
} |
|
|
if (nread < 0) { |
if (nread < 0) { |
err: if (unlink(rfp->rf_path) == -1) |
err: if (unlink(rfp->rf_path) == -1) |
cvs_log(LP_ERRNO, |
cvs_log(LP_ERRNO, |
|
|
free(bp); |
free(bp); |
return (-1); |
return (-1); |
} |
} |
|
|
close(from_fd); |
close(from_fd); |
close(to_fd); |
close(to_fd); |
free(bp); |
free(bp); |
|
|
if (unlink(fn) == -1) { |
if (unlink(fn) == -1) { |
cvs_log(LP_ERRNO, |
cvs_log(LP_ERRNO, |
"failed to unlink `%s'", |
"failed to unlink `%s'", fn); |
fn); |
|
return (-1); |
return (-1); |
} |
} |
} else { |
} else { |
|
|
return (-1); |
return (-1); |
} |
} |
} |
} |
|
|
if ((chmod(rfp->rf_path, S_IRUSR|S_IRGRP|S_IROTH) == -1)) { |
if ((chmod(rfp->rf_path, S_IRUSR|S_IRGRP|S_IROTH) == -1)) { |
cvs_log(LP_ERRNO, "failed to chmod `%s'", |
cvs_log(LP_ERRNO, "failed to chmod `%s'", |
rfp->rf_path); |
rfp->rf_path); |
return (-1); |
return (-1); |
} |
} |
|
|
rfp->rf_flags |= RCS_SYNCED; |
rfp->rf_flags |= RCS_SYNCED; |
|
|
return (0); |
return (0); |