about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndreyDobrovolskyOdessa <andrey.dobrovolsky.odessa@gmail.com>2021-03-18 13:06:51 +0200
committerLeah Neukirchen <leah@vuxu.org>2021-03-19 15:18:21 +0100
commit27e52f88774c1e61fef46ace84cde6f3160b2761 (patch)
tree766db3144351b6c469076ac1478f2698b0eaa210
parent1390a76b97dec19c77486f2995a5018a10ae35da (diff)
downloadredo-c-27e52f88774c1e61fef46ace84cde6f3160b2761.tar.gz
redo-c-27e52f88774c1e61fef46ace84cde6f3160b2761.tar.xz
redo-c-27e52f88774c1e61fef46ace84cde6f3160b2761.zip
Changing order of creating files on find_dofile in run_script()
In case of missing .do file .lock, .depend and .target files remains in the
target directory. Calling find_dofile() before creating them helps to avoid
such target directory pollution.

Closes: #15 [via git-merge-pr]
-rw-r--r--redo.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/redo.c b/redo.c
index ef130f0..a702d0d 100644
--- a/redo.c
+++ b/redo.c
@@ -627,6 +627,12 @@ run_script(char *target, int implicit)
 
 	target = targetchdir(target);
 
+	dofile = find_dofile(target);
+	if (!dofile) {
+		fprintf(stderr, "no dofile for %s.\n", target);
+		exit(1);
+	}
+
 	int lock_fd = open(targetlock(target),
 	    O_WRONLY | O_TRUNC | O_CREAT, 0666);
 	if (lockf(lock_fd, F_TLOCK, 0) < 0) {
@@ -645,12 +651,6 @@ run_script(char *target, int implicit)
 
 	target_fd = mkstemp(temp_target_base);
 
-	dofile = find_dofile(target);
-	if (!dofile) {
-		fprintf(stderr, "no dofile for %s.\n", target);
-		exit(1);
-	}
-
 	fprintf(stderr, "redo%*.*s %s # %s\n", level*2, level*2, " ", orig_target, dofile);
 	write_dep(dep_fd, dofile);