aboutsummaryrefslogtreecommitdiff
path: root/find.cc
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-10-09 16:35:54 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-10-09 16:35:54 +0900
commitbd3bb23181d6bc220f64dc253ae76259611d6a61 (patch)
tree568230c23f31687fbc487fc9f41d4af3af0ee485 /find.cc
parentc58db99fcb36c54b8bf48d8fa8f52c7bc8e09761 (diff)
downloadkati-bd3bb23181d6bc220f64dc253ae76259611d6a61.tar.gz
[C++] Fix FindEmulator for paths in symlinks
Diffstat (limited to 'find.cc')
-rw-r--r--find.cc26
1 files changed, 22 insertions, 4 deletions
diff --git a/find.cc b/find.cc
index eb796f1..f50a5ec 100644
--- a/find.cc
+++ b/find.cc
@@ -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",