diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-03-22 14:33:50 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-03-22 14:33:50 +0100 |
commit | e05965d4f65ab3ead7e9b1a9c6433feddb8a087e (patch) | |
tree | 935ce9f2569cb24a83f71bfd8e608616e59b09d2 | |
parent | 4a2d79ff737dc1892c06e01a0caef36c218fa76d (diff) | |
download | redo-c-e05965d4f65ab3ead7e9b1a9c6433feddb8a087e.tar.gz redo-c-e05965d4f65ab3ead7e9b1a9c6433feddb8a087e.tar.xz redo-c-e05965d4f65ab3ead7e9b1a9c6433feddb8a087e.zip |
check_deps: keep track of proper pwd when recursing
Else, a dependency to a subdirectory would change into it, but then look up the subdirectory-relative names in the .dep file according to the dir_fd of the parent. Now, we keep dir_fd updated, and ensure after each .dep line we return to it.
-rw-r--r-- | redo.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/redo.c b/redo.c index 84f1478..ea5fb8d 100644 --- a/redo.c +++ b/redo.c @@ -343,6 +343,16 @@ datefile(int fd) return hexdate; } +static int +keepdir() { + int fd = open(".", O_RDONLY | O_DIRECTORY | O_CLOEXEC); + if (fd < 0) { + perror("dir open"); + exit(-1); + } + return fd; +} + static char * targetchdir(char *target) { char *base = strrchr(target, '/'); @@ -395,6 +405,7 @@ check_deps(char *target) FILE *f; int ok = 1; int fd; + int old_dir_fd = dir_fd; target = targetchdir(target); @@ -406,6 +417,8 @@ check_deps(char *target) if (!f) return 0; + dir_fd = keepdir(); + while (ok && !feof(f)) { char line[4096]; char *hash = line + 1; @@ -431,8 +444,10 @@ check_deps(char *target) } // hash is good, recurse into dependencies if (ok && strcmp(target, filename) != 0 && - !sourcefile(filename)) + !sourcefile(filename)) { ok = check_deps(filename); + fchdir(dir_fd); + } break; case '!': // always rebuild default: // dep file broken, lets recreate it @@ -448,6 +463,9 @@ check_deps(char *target) fclose(f); + close(dir_fd); + dir_fd = old_dir_fd; + return ok; } @@ -916,11 +934,7 @@ main(int argc, char *argv[]) argv[0] = (char *) "all"; // XXX safe? } - dir_fd = open(".", O_RDONLY | O_DIRECTORY | O_CLOEXEC); - if (dir_fd < 0) { - perror("dir open"); - exit(-1); - } + dir_fd = keepdir(); if (strcmp(program, "redo") == 0) { fflag = 1; |