summaryrefslogtreecommitdiffstats
path: root/third_party
diff options
context:
space:
mode:
authordgrogan@chromium.org <dgrogan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-19 22:13:42 +0000
committerdgrogan@chromium.org <dgrogan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-19 22:13:42 +0000
commite35e1736650839e67d5ef43cc2a090b8a9e43a17 (patch)
treedcbe491511af64f3cdd910560c7e6a42de9d2af7 /third_party
parent62558f12eadaf86fa9c1223889b13fcb0261ff14 (diff)
downloadchromium_src-e35e1736650839e67d5ef43cc2a090b8a9e43a17.zip
chromium_src-e35e1736650839e67d5ef43cc2a090b8a9e43a17.tar.gz
chromium_src-e35e1736650839e67d5ef43cc2a090b8a9e43a17.tar.bz2
Report errors from ChromiumEnv::GetChildren in Posix.
Win forthcoming. BUG=308101 Review URL: https://codereview.chromium.org/26513005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229622 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r--third_party/leveldatabase/env_chromium.cc66
-rw-r--r--third_party/leveldatabase/env_chromium.h1
2 files changed, 57 insertions, 10 deletions
diff --git a/third_party/leveldatabase/env_chromium.cc b/third_party/leveldatabase/env_chromium.cc
index 331e6e9..2eb935b 100644
--- a/third_party/leveldatabase/env_chromium.cc
+++ b/third_party/leveldatabase/env_chromium.cc
@@ -37,6 +37,7 @@
#endif
#if defined(OS_POSIX)
+#include <dirent.h>
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/time.h>
@@ -315,6 +316,8 @@ const char* MethodIDToString(MethodID method) {
return "NewLogger";
case kSyncParent:
return "SyncParent";
+ case kGetChildren:
+ return "GetChildren";
case kNumEntries:
NOTREACHED();
return "kNumEntries";
@@ -668,21 +671,64 @@ void ChromiumEnv::RestoreIfNecessary(const std::string& dir,
}
}
-Status ChromiumEnv::GetChildren(const std::string& dir,
- std::vector<std::string>* result) {
- result->clear();
- // TODO(jorlow): Unfortunately, the FileEnumerator swallows errors, so
- // we'll always return OK. Maybe manually check for error
- // conditions like the file not existing?
- base::FileEnumerator iter(
- CreateFilePath(dir), false, base::FileEnumerator::FILES);
+namespace {
+#if defined(OS_WIN)
+static base::PlatformFileError GetDirectoryEntries(
+ const base::FilePath& dir_filepath,
+ std::vector<base::FilePath>* result) {
+ // TODO(dgrogan): Replace with FindFirstFile / FindNextFile. Note that until
+ // that happens this is filtering out directories whereas the Posix version
+ // below is not. There shouldn't be any directories so this shouldn't be an
+ // issue.
+ base::FileEnumerator iter(dir_filepath, false, base::FileEnumerator::FILES);
base::FilePath current = iter.Next();
while (!current.empty()) {
- result->push_back(FilePathToString(current.BaseName()));
+ result->push_back(current.BaseName());
current = iter.Next();
}
+ return base::PLATFORM_FILE_OK;
+}
+#else
+static base::PlatformFileError GetDirectoryEntries(
+ const base::FilePath& dir_filepath,
+ std::vector<base::FilePath>* result) {
+ const std::string dir_string = FilePathToString(dir_filepath);
+ result->clear();
+ DIR* dir = opendir(dir_string.c_str());
+ if (!dir)
+ return base::ErrnoToPlatformFileError(errno);
+ struct dirent dent_buf;
+ struct dirent* dent;
+ int readdir_result;
+ while ((readdir_result = readdir_r(dir, &dent_buf, &dent)) == 0 && dent)
+ result->push_back(CreateFilePath(dent->d_name));
+ int saved_errno = errno;
+ closedir(dir);
+ if (readdir_result != 0)
+ return base::ErrnoToPlatformFileError(saved_errno);
+ return base::PLATFORM_FILE_OK;
+}
+#endif
+}
+
+Status ChromiumEnv::GetChildren(const std::string& dir_string,
+ std::vector<std::string>* result) {
+ std::vector<base::FilePath> entries;
+ base::PlatformFileError error =
+ GetDirectoryEntries(CreateFilePath(dir_string), &entries);
+ if (error != base::PLATFORM_FILE_OK) {
+ RecordOSError(kGetChildren, error);
+ return MakeIOError(
+ dir_string, "Could not open/read directory", kGetChildren, error);
+ }
+ for (std::vector<base::FilePath>::iterator it = entries.begin();
+ it != entries.end();
+ ++it) {
+ result->push_back(FilePathToString(*it));
+ }
+
if (make_backup_)
- RestoreIfNecessary(dir, result);
+ RestoreIfNecessary(dir_string, result);
return Status::OK();
}
diff --git a/third_party/leveldatabase/env_chromium.h b/third_party/leveldatabase/env_chromium.h
index 740a1e0..3afd462 100644
--- a/third_party/leveldatabase/env_chromium.h
+++ b/third_party/leveldatabase/env_chromium.h
@@ -41,6 +41,7 @@ enum MethodID {
kGetTestDirectory,
kNewLogger,
kSyncParent,
+ kGetChildren,
kNumEntries
};