Chromium Code Reviews| Index: webrtc/test/testsupport/fileutils.cc |
| diff --git a/webrtc/test/testsupport/fileutils.cc b/webrtc/test/testsupport/fileutils.cc |
| index 02ef06580bbcec4203d46ac1c23f42d4e279ebd6..922e58ffb2b43033e50f716687a363a00eae6021 100644 |
| --- a/webrtc/test/testsupport/fileutils.cc |
| +++ b/webrtc/test/testsupport/fileutils.cc |
| @@ -24,6 +24,7 @@ |
| #include "webrtc/base/win32.h" |
| #define GET_CURRENT_DIR _getcwd |
| #else |
| +#include <dirent.h> |
| #include <unistd.h> |
| #define GET_CURRENT_DIR getcwd |
| @@ -40,6 +41,7 @@ |
| #include <memory> |
| +#include "webrtc/base/checks.h" |
| #include "webrtc/typedefs.h" // For architecture defines |
| namespace webrtc { |
| @@ -76,6 +78,64 @@ const char* kResourcesDirName = "resources"; |
| char relative_dir_path[FILENAME_MAX]; |
| bool relative_dir_path_set = false; |
| +#ifdef WIN32 |
| +rtc::Optional<std::vector<std::string>> ReadDirectoryWin(std::string path) { |
| + if (path.length() == 0) |
| + return rtc::Optional<std::vector<std::string>>(); |
|
kwiberg-webrtc
2017/05/30 08:28:12
This check is the same in both versions, so move t
AleBzk
2017/05/30 11:09:16
Done.
|
| + |
| + // Append separator character if needed. |
| + if (path.back() != '\\') |
| + path += '\\'; |
| + |
| + // Init. |
| + WIN32_FIND_DATA data; |
| + HANDLE handle = ::FindFirstFile(rtc::ToUtf16(path + '*').c_str(), &data); |
| + if (handle == INVALID_HANDLE_VALUE) |
| + return rtc::Optional<std::vector<std::string>>(); |
| + |
| + // Populate output. |
| + std::vector<std::string> found_entries; |
| + do { |
| + const std::string name = rtc::ToUtf8(data.cFileName); |
| + if (name != "." && name != "..") |
| + found_entries.emplace_back(path + name); |
| + } while (::FindNextFile(handle, &data) == TRUE); |
| + |
| + // Release resources. |
| + if (handle != INVALID_HANDLE_VALUE) |
| + ::FindClose(handle); |
| + |
| + return rtc::Optional<std::vector<std::string>>(std::move(found_entries)); |
| +} |
| +#else |
| +rtc::Optional<std::vector<std::string>> ReadDirectoryNotWin(std::string path) { |
| + if (path.length() == 0) |
| + return rtc::Optional<std::vector<std::string>>(); |
| + |
| + // Append separator character if needed. |
| + if (path.back() != '/') |
| + path += '/'; |
| + |
| + // Init. |
| + DIR* dir = ::opendir(path.c_str()); |
| + if (dir == nullptr) |
| + return rtc::Optional<std::vector<std::string>>(); |
| + |
| + // Populate output. |
| + std::vector<std::string> found_entries; |
| + while (dirent* dirent = readdir(dir)) { |
| + const std::string& name = dirent->d_name; |
| + if (name != "." && name != "..") |
| + found_entries.emplace_back(path + name); |
| + } |
| + |
| + // Release resources. |
| + closedir(dir); |
| + |
| + return rtc::Optional<std::vector<std::string>>(std::move(found_entries)); |
| +} |
| +#endif |
| + |
| } // namespace |
| const char* kCannotFindProjectRootDir = "ERROR_CANNOT_FIND_PROJECT_ROOT_DIR"; |
| @@ -126,7 +186,7 @@ std::string WorkingDir() { |
| return kRootDirName; |
| } |
| -#else // WEBRTC_ANDROID |
| +#else // WEBRTC_ANDROID |
| std::string ProjectRootPath() { |
| #if defined(WEBRTC_IOS) |
| @@ -212,6 +272,14 @@ std::string TempFilename(const std::string &dir, const std::string &prefix) { |
| #endif |
| } |
| +rtc::Optional<std::vector<std::string>> ReadDirectory(const std::string& path) { |
|
kwiberg-webrtc
2017/05/30 08:28:12
Wait, didn't you just explain to me why path shoul
AleBzk
2017/05/30 11:09:16
Just wanted to avoid an unnecessary extra copy. Th
|
| +#if defined(WEBRTC_WIN) |
| + return ReadDirectoryWin(path); |
| +#else |
| + return ReadDirectoryNotWin(path); |
| +#endif |
| +} |
| + |
| bool CreateDir(const std::string& directory_name) { |
| struct stat path_info = {0}; |
| // Check if the path exists already: |