diff options
author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-10-09 16:35:54 +0900 |
---|---|---|
committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2015-10-09 16:35:54 +0900 |
commit | bd3bb23181d6bc220f64dc253ae76259611d6a61 (patch) | |
tree | 568230c23f31687fbc487fc9f41d4af3af0ee485 | |
parent | c58db99fcb36c54b8bf48d8fa8f52c7bc8e09761 (diff) | |
download | kati-bd3bb23181d6bc220f64dc253ae76259611d6a61.tar.gz |
[C++] Fix FindEmulator for paths in symlinks
-rw-r--r-- | find.cc | 26 | ||||
-rw-r--r-- | testcase/find_command.mk | 8 |
2 files changed, 30 insertions, 4 deletions
@@ -28,6 +28,7 @@ //#undef NOLOG +#include "fileutil.h" #include "log.h" #include "string_piece.h" #include "strutil.h" @@ -663,6 +664,14 @@ class FindEmulatorImpl : public FindEmulator { !HasPrefix(s, "out")); } + const DirentNode* FindDir(StringPiece d, bool* should_fallback) { + const DirentNode* r = root_->FindDir(d); + if (!r) { + *should_fallback = Exists(d); + } + return r; + } + virtual bool HandleFind(const string& cmd UNUSED, const FindCommand& fc, string* out) override { if (!CanHandle(fc.chdir)) { @@ -684,10 +693,11 @@ class FindEmulatorImpl : public FindEmulator { SPF(fc.testdir), cmd.c_str()); return false; } - if (!root_->FindDir(fc.testdir)) { + bool should_fallback = false; + if (!FindDir(fc.testdir, &should_fallback)) { LOG("FindEmulator: Test dir (%.*s) not found: %s", SPF(fc.testdir), cmd.c_str()); - return true; + return !should_fallback; } } @@ -697,7 +707,10 @@ class FindEmulatorImpl : public FindEmulator { SPF(fc.chdir), cmd.c_str()); return false; } - if (!root_->FindDir(fc.chdir)) { + bool should_fallback = false; + if (!FindDir(fc.chdir, &should_fallback)) { + if (should_fallback) + return false; if (!fc.redirect_to_devnull) { fprintf(stderr, "FindEmulator: cd: %.*s: No such file or directory\n", @@ -718,8 +731,13 @@ class FindEmulatorImpl : public FindEmulator { return false; } - const DirentNode* base = root_->FindDir(dir); + bool should_fallback = false; + const DirentNode* base = FindDir(dir, &should_fallback); if (!base) { + if (should_fallback) { + out->resize(orig_out_size); + return false; + } if (!fc.redirect_to_devnull) { fprintf(stderr, "FindEmulator: find: `%s': No such file or directory\n", diff --git a/testcase/find_command.mk b/testcase/find_command.mk index 0947091..c37198a 100644 --- a/testcase/find_command.mk +++ b/testcase/find_command.mk @@ -33,6 +33,9 @@ test1: mkdir -p build/tools cp ../../testcase/tools/findleaves.py build/tools + mkdir -p testdir3/b/c/d + ln -s b testdir3/a + test2: @echo no options $(call run_find, find testdir) @@ -105,3 +108,8 @@ endif @echo missing chdir / testdir $(call run_find, cd xxx && find .) $(call run_find, if [ -d xxx ]; then find .; fi) + +test3: + $(call run_find, find testdir3/a/c) + $(call run_find, if [ -d testdir3/a/c ]; then find testdir3/a/c; fi) + $(call run_find, cd testdir3/a/c && find .) |