summaryrefslogtreecommitdiff
path: root/usr.bin/cvs
diff options
context:
space:
mode:
authorJean-Francois Brousseau <jfb@cvs.openbsd.org>2004-07-14 05:16:05 +0000
committerJean-Francois Brousseau <jfb@cvs.openbsd.org>2004-07-14 05:16:05 +0000
commit1b846e86fa3a06aa5111f79f2d6ac63df04c78a7 (patch)
tree1d337c61c3e2a992ee95286c5903a3d4f3ecc885 /usr.bin/cvs
parent4543e2f0eea57e90ff2e949f32eb9e7d4d50853a (diff)
make adding entries to the Entries file work
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r--usr.bin/cvs/entries.c79
-rw-r--r--usr.bin/cvs/proto.c11
2 files changed, 72 insertions, 18 deletions
diff --git a/usr.bin/cvs/entries.c b/usr.bin/cvs/entries.c
index 18cfcb20b97..f838961c1e2 100644
--- a/usr.bin/cvs/entries.c
+++ b/usr.bin/cvs/entries.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: entries.c,v 1.2 2004/07/14 04:32:42 jfb Exp $ */
+/* $OpenBSD: entries.c,v 1.3 2004/07/14 05:16:04 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -41,6 +41,11 @@
#define CVS_ENTRIES_DELIM '/'
+
+static struct cvs_ent* cvs_ent_clone (const struct cvs_ent *);
+
+
+
/*
* cvs_ent_open()
*
@@ -53,13 +58,23 @@ CVSENTRIES*
cvs_ent_open(const char *dir, int flags)
{
size_t len;
- char entpath[MAXPATHLEN], ebuf[128];
+ char entpath[MAXPATHLEN], ebuf[128], mode[4];
FILE *fp;
struct cvs_ent *ent;
CVSENTRIES *ep;
+ memset(mode, 0, sizeof(mode));
+ if (flags & O_RDONLY)
+ mode[0] = 'r';
+ else if (flags & O_WRONLY)
+ mode[0] = 'w';
+ else if (flags & O_RDWR) {
+ mode[0] = 'r';
+ mode[1] = '+';
+ }
+
snprintf(entpath, sizeof(entpath), "%s/" CVS_PATH_ENTRIES, dir);
- fp = fopen(entpath, "r");
+ fp = fopen(entpath, mode);
if (fp == NULL) {
cvs_log(LP_ERRNO, "cannot open CVS/Entries for reading",
entpath);
@@ -84,6 +99,10 @@ cvs_ent_open(const char *dir, int flags)
ep->cef_entries = NULL;
ep->cef_nbent = 0;
+ /* only keep a pointer to the open file if we're in writing mode */
+ if ((flags & O_WRONLY) || (flags & O_RDWR))
+ ep->cef_file = fp;
+
while (fgets(ebuf, sizeof(ebuf), fp) != NULL) {
len = strlen(ebuf);
if ((len > 0) && (ebuf[len - 1] == '\n'))
@@ -120,31 +139,73 @@ cvs_ent_close(CVSENTRIES *ep)
/*
* cvs_ent_add()
*
- * Add the entry <ent>
+ * Add the entry <ent> to the Entries file <ef>.
*/
int
cvs_ent_add(CVSENTRIES *ef, struct cvs_ent *ent)
{
void *tmp;
- struct cvs_ent *entp;
+
+ if (ef->cef_file == NULL) {
+ cvs_log(LP_ERR, "Entries file is opened in read-only mode");
+ return (-1);
+ }
if (cvs_ent_get(ef, ent->ce_name) != NULL)
return (-1);
- entp = cvs_ent_parse(ent->ce_line);
- if (entp == NULL) {
+ if (fseek(ef->cef_file, (long)0, SEEK_END) == -1) {
+ cvs_log(LP_ERRNO, "failed to seek to end of CVS/Entries file");
+ return (-1);
+ }
+ fprintf(ef->cef_file, "%s\n", ent->ce_line);
+
+ tmp = realloc(ef->cef_entries, (ef->cef_nbent + 1) * sizeof(ent));
+ if (tmp == NULL) {
+ cvs_log(LP_ERRNO, "failed to resize entries buffer");
+ return (-1);
+ }
+
+ ef->cef_entries = (struct cvs_ent **)tmp;
+ ef->cef_entries[ef->cef_nbent++] = ent;
+
+ return (0);
+}
+
+
+/*
+ * cvs_ent_addln()
+ *
+ * Add a line to the Entries file.
+ */
+
+int
+cvs_ent_addln(CVSENTRIES *ef, const char *line)
+{
+ void *tmp;
+ struct cvs_ent *ent;
+
+ if (ef->cef_file == NULL) {
+ cvs_log(LP_ERR, "Entries file is opened in read-only mode");
return (-1);
}
- tmp = realloc(ef->cef_entries, (ef->cef_nbent + 1) * sizeof(entp));
+ ent = cvs_ent_parse(line);
+ if (ent == NULL)
+ return (-1);
+
+ if (cvs_ent_get(ef, ent->ce_name) != NULL)
+ return (-1);
+
+ tmp = realloc(ef->cef_entries, (ef->cef_nbent + 1) * sizeof(ent));
if (tmp == NULL) {
cvs_log(LP_ERRNO, "failed to resize entries buffer");
return (-1);
}
ef->cef_entries = (struct cvs_ent **)tmp;
- ef->cef_entries[ef->cef_nbent++] = entp;
+ ef->cef_entries[ef->cef_nbent++] = ent;
return (0);
}
diff --git a/usr.bin/cvs/proto.c b/usr.bin/cvs/proto.c
index 96bd31ac0f7..43bf8861bcb 100644
--- a/usr.bin/cvs/proto.c
+++ b/usr.bin/cvs/proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proto.c,v 1.2 2004/07/14 04:32:42 jfb Exp $ */
+/* $OpenBSD: proto.c,v 1.3 2004/07/14 05:16:04 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -582,7 +582,6 @@ static int
cvs_resp_newentry(int type, char *line)
{
char entbuf[128], path[MAXPATHLEN];
- struct cvs_ent *entp;
CVSENTRIES *entfile;
snprintf(path, sizeof(path), "%s/" CVS_PATH_ENTRIES, line);
@@ -594,16 +593,10 @@ cvs_resp_newentry(int type, char *line)
if (cvs_client_getln(entbuf, sizeof(entbuf)) < 0)
return (-1);
- entp = cvs_ent_parse(entbuf);
- if (entp == NULL)
- return (-1);
-
entfile = cvs_ent_open(path, O_WRONLY);
if (entfile == NULL)
return (-1);
-
- cvs_ent_add(entfile, entp);
-
+ cvs_ent_addln(entfile, entbuf);
cvs_ent_close(entfile);
return (0);