-/* $OpenBSD: extern.h,v 1.224 2024/06/08 13:30:35 tb Exp $ */
+/* $OpenBSD: extern.h,v 1.225 2024/07/12 09:27:32 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
void proc_rrdp(int) __attribute__((noreturn));
/* Repository handling */
-int filepath_add(struct filepath_tree *, char *, int, time_t);
+int filepath_add(struct filepath_tree *, char *, int, time_t, int);
+int filepath_valid(struct filepath_tree *, char *, int);
void rrdp_clear(unsigned int);
void rrdp_session_save(unsigned int, struct rrdp_session *);
void rrdp_session_free(struct rrdp_session *);
-/* $OpenBSD: main.c,v 1.261 2024/07/12 08:54:48 claudio Exp $ */
+/* $OpenBSD: main.c,v 1.262 2024/07/12 09:27:32 claudio Exp $ */
/*
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
if (filemode)
goto done;
- if (filepath_add(&fpt, file, talid, mtime) == 0) {
+ if (filepath_valid(&fpt, file, talid)) {
warnx("%s: File already visited", file);
goto done;
}
break;
}
+ if (filepath_add(&fpt, file, talid, mtime, ok) == 0)
+ errx(1, "%s: File already in tree", file);
+
done:
free(file);
entity_queue--;
-/* $OpenBSD: repo.c,v 1.60 2024/06/07 08:22:53 claudio Exp $ */
+/* $OpenBSD: repo.c,v 1.61 2024/07/12 09:27:32 claudio Exp $ */
/*
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
* Functions to lookup which files have been accessed during computation.
*/
int
-filepath_add(struct filepath_tree *tree, char *file, int id, time_t mtime)
+filepath_add(struct filepath_tree *tree, char *file, int id, time_t mtime,
+ int ok)
{
struct filepath *fp, *rfp;
return 0;
fp = rfp;
}
- fp->talmask |= (1 << id);
+ if (ok)
+ fp->talmask |= (1 << id);
return 1;
}
return filepath_find(tree, file) != NULL;
}
+/*
+ * Returns true if file exists and the id bit is set and ok flag is true.
+ */
+int
+filepath_valid(struct filepath_tree *tree, char *file, int id)
+{
+ struct filepath *fp;
+
+ if ((fp = filepath_find(tree, file)) == NULL)
+ return 0;
+ return (fp->talmask & (1 << id)) != 0;
+}
+
/*
* Remove entry from tree and free it.
*/
/* write new content or mark uri as deleted. */
if (pt == PUB_DEL) {
- filepath_add(&rr->deleted, uri, 0, 0);
+ filepath_add(&rr->deleted, uri, 0, 0, 1);
} else {
fp = filepath_find(&rr->deleted, uri);
if (fp != NULL) {
static void
repo_move_valid(struct filepath_tree *tree)
{
- struct filepath *fp, *nfp;
+ struct filepath *fp, *nfp, *ofp;
size_t rsyncsz = strlen(".rsync/");
size_t rrdpsz = strlen(".rrdp/");
size_t tasz = strlen(".ta/");
if (repo_mkpath(AT_FDCWD, fn) == -1)
continue;
- if (rename(fp->file, fn) == -1) {
- warn("rename %s", fp->file);
- continue;
- }
-
/* switch filepath node to new path */
RB_REMOVE(filepath_tree, tree, fp);
base = fp->file;
if ((fp->file = strdup(fn)) == NULL)
err(1, NULL);
+
+ again:
+ if ((ofp = RB_INSERT(filepath_tree, tree, fp)) != NULL) {
+ if (ofp->talmask == 0) {
+ /* conflicting path is not valid, drop it */
+ filepath_put(tree, ofp);
+ goto again;
+ }
+ if (fp->talmask != 0) {
+ warnx("%s: file already present in "
+ "validated cache", fp->file);
+ }
+ free(fp->file);
+ free(fp);
+ free(base);
+ continue;
+ }
+
+ if (rename(base, fp->file) == -1)
+ warn("rename to %s", fp->file);
+
free(base);
- if (RB_INSERT(filepath_tree, tree, fp) != NULL)
- errx(1, "%s: both possibilities of file present",
- fp->file);
}
}