diff options
author | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2008-06-19 19:03:26 +0000 |
---|---|---|
committer | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2008-06-19 19:03:26 +0000 |
commit | 1179c305ed0961619a7d5da9be4504bed3b2b0d0 (patch) | |
tree | d1abc23d99de97124b1ab140300433a6790523f1 /usr.bin | |
parent | 0fa09dc5d4739d4dc334ab186486a4a58448fd6f (diff) |
Add entries to history file only if it already exists.
ok joris
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/history.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/usr.bin/cvs/history.c b/usr.bin/cvs/history.c index 15f9fb134ec..05d9e7ecc9b 100644 --- a/usr.bin/cvs/history.c +++ b/usr.bin/cvs/history.c @@ -1,4 +1,4 @@ -/* $OpenBSD: history.c,v 1.38 2008/06/11 00:47:05 tobias Exp $ */ +/* $OpenBSD: history.c,v 1.39 2008/06/19 19:03:25 tobias Exp $ */ /* * Copyright (c) 2007 Joris Vink <joris@openbsd.org> * @@ -19,6 +19,7 @@ #include <ctype.h> #include <errno.h> +#include <fcntl.h> #include <pwd.h> #include <stdlib.h> #include <string.h> @@ -67,6 +68,7 @@ cvs_history_add(int type, struct cvs_file *cf, const char *argument) FILE *fp; RCSNUM *hrev; size_t len; + int fd; char *cwd, *p, *rev; char revbuf[CVS_REV_BUFSZ], repo[MAXPATHLEN], fpath[MAXPATHLEN]; char timebuf[CVS_TIME_BUFSZ]; @@ -162,14 +164,20 @@ cvs_history_add(int type, struct cvs_file *cf, const char *argument) (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", current_cvsroot->cr_dir, CVS_PATH_HISTORY); - if ((fp = fopen(fpath, "a")) != NULL) { - fprintf(fp, "%c%x|%s|%s|%s|%s|%s\n", - historytab[type], time(NULL), getlogin(), cwd, repo, - rev, (cf != NULL) ? cf->file_name : argument); - - (void)fclose(fp); + if ((fd = open(fpath, O_WRONLY|O_APPEND)) == -1) { + if (errno != ENOENT) + cvs_log(LP_ERR, "failed to open history file"); } else { - cvs_log(LP_ERR, "failed to add entry to history file"); + if ((fp = fdopen(fd, "a")) != NULL) { + fprintf(fp, "%c%x|%s|%s|%s|%s|%s\n", + historytab[type], time(NULL), getlogin(), cwd, + repo, rev, (cf != NULL) ? cf->file_name : + argument); + (void)fclose(fp); + } else { + cvs_log(LP_ERR, "failed to add entry to history file"); + (void)close(fd); + } } if (rev != revbuf) |