diff options
| author | Dan Willemsen <dwillemsen@google.com> | 2017-02-23 00:10:04 -0800 |
|---|---|---|
| committer | Dan Willemsen <dwillemsen@google.com> | 2017-02-23 00:27:57 -0800 |
| commit | 6f3f0f41f364a3ed7533cd075792ca38aef8ecf6 (patch) | |
| tree | cb02733522afc9287d01242fe93bdfc30e9fa423 | |
| parent | f8e155865652181a504d7400afd25f35cf158472 (diff) | |
Be more resilient to directories disappearing during startup
In multiproduct_build, we run a lot of kati instances in the same source
tree, but pointing to different out folders. I'm removing the out
folders of successful runs so that too much disk space isn't used
(unless the user requests it). But I often see a kati PERROR about
opendir failing, since it's trying to set up the find emulator while a
different configuration's output directory is being removed.
This was also hit by #109 in similar circumstances.
| -rw-r--r-- | find.cc | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -793,6 +793,9 @@ class FindEmulatorImpl : public FindEmulator { if (!is_initialized_) { ScopedTimeReporter tr("init find emulator time"); root_.reset(ConstructDirectoryTree("")); + if (!root_) { + ERROR("FindEmulator: Cannot open root directory"); + } ResolveSymlinks(); LOG_STAT("%d find nodes", node_cnt_); is_initialized_ = true; @@ -916,8 +919,14 @@ class FindEmulatorImpl : public FindEmulator { DirentNode* ConstructDirectoryTree(const string& path) { DIR* dir = opendir(path.empty() ? "." : path.c_str()); - if (!dir) - PERROR("opendir failed: %s", path.c_str()); + if (!dir) { + if (errno == ENOENT) { + LOG("opendir failed: %s", path.c_str()); + return NULL; + } else { + PERROR("opendir failed: %s", path.c_str()); + } + } DirentDirNode* n = new DirentDirNode(path); @@ -942,6 +951,9 @@ class FindEmulatorImpl : public FindEmulator { } if (d_type == DT_DIR) { c = ConstructDirectoryTree(npath); + if (c == NULL) { + continue; + } } else if (d_type == DT_LNK) { auto s = new DirentSymlinkNode(npath); symlinks_.push_back(make_pair(npath, s)); @@ -994,7 +1006,12 @@ class FindEmulatorImpl : public FindEmulator { if (type == DT_DIR) { if (path.find('/') == string::npos) { - s->set_to(ConstructDirectoryTree(path)); + DirentNode* dir = ConstructDirectoryTree(path); + if (dir != NULL) { + s->set_to(dir); + } else { + s->set_errno(errno); + } } } else if (type != DT_LNK && type != DT_UNKNOWN) { s->set_to(new DirentFileNode(path, type)); |
