aboutsummaryrefslogtreecommitdiffstats
path: root/find.cc
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-10-15 16:51:09 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-10-15 17:56:27 +0900
commit407d8d46b5ad545b7a6ef8ba930c6e08880e4b47 (patch)
tree9f3569e5c204088990c4ebd6492f4d5ab8508265 /find.cc
parent31505bafc91cba6dd491975bb707fc7c883fa8b4 (diff)
downloadandroid_build_kati-407d8d46b5ad545b7a6ef8ba930c6e08880e4b47.tar.gz
android_build_kati-407d8d46b5ad545b7a6ef8ba930c6e08880e4b47.tar.bz2
android_build_kati-407d8d46b5ad545b7a6ef8ba930c6e08880e4b47.zip
[C++] Resolve symlinks in the top directory
Diffstat (limited to 'find.cc')
-rw-r--r--find.cc23
1 files changed, 19 insertions, 4 deletions
diff --git a/find.cc b/find.cc
index dd5b7fa..4c7cd8f 100644
--- a/find.cc
+++ b/find.cc
@@ -308,6 +308,12 @@ class DirentSymlinkNode : public DirentNode {
: DirentNode(name), to_(NULL), errno_(0) {
}
+ virtual const DirentNode* FindDir(StringPiece d) const {
+ if (errno_ == 0 && to_)
+ return to_->FindDir(d);
+ return NULL;
+ }
+
virtual bool RunFind(const FindCommand& fc, int d,
string* path,
unordered_map<const DirentNode*, string>* cur_read_dirs,
@@ -897,7 +903,10 @@ class FindEmulatorImpl : public FindEmulator {
buf[len] = 0;
struct stat st;
- if (stat(path.c_str(), &st) < 0) {
+ unsigned char type = DT_UNKNOWN;
+ if (stat(path.c_str(), &st) == 0) {
+ type = GetDtTypeFromStat(st);
+ } else {
s->set_errno(errno);
LOG("stat failed: %s: %s", path.c_str(), strerror(errno));
}
@@ -912,11 +921,17 @@ class FindEmulatorImpl : public FindEmulator {
}
}
- unsigned char type = GetDtTypeFromStat(st);
- if (type != DT_DIR && type != DT_LNK) {
- s->set_to(new DirentFileNode(path, type));
+ if (type == DT_DIR) {
+ if (path.find('/') == string::npos) {
+ s->set_to(ConstructDirectoryTree(path));
+ }
+ } else if (type != DT_LNK && type != DT_UNKNOWN) {
+ s->set_to(new DirentFileNode(path, type));
}
}
+
+ if (!symlinks_.empty())
+ ResolveSymlinks();
}
unique_ptr<DirentNode> root_;