Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/test/testsupport/fileutils.h" | 11 #include "webrtc/test/testsupport/fileutils.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 | 14 |
| 15 #ifdef WIN32 | 15 #ifdef WIN32 |
| 16 #include <direct.h> | 16 #include <direct.h> |
| 17 #include <tchar.h> | 17 #include <tchar.h> |
| 18 #include <windows.h> | 18 #include <windows.h> |
| 19 #include <algorithm> | 19 #include <algorithm> |
| 20 | 20 |
| 21 #include "Shlwapi.h" | 21 #include "Shlwapi.h" |
| 22 #include "WinDef.h" | 22 #include "WinDef.h" |
| 23 | 23 |
| 24 #include "webrtc/base/win32.h" | 24 #include "webrtc/base/win32.h" |
| 25 #define GET_CURRENT_DIR _getcwd | 25 #define GET_CURRENT_DIR _getcwd |
| 26 #else | 26 #else |
| 27 #include <dirent.h> | |
| 27 #include <unistd.h> | 28 #include <unistd.h> |
| 28 | 29 |
| 29 #define GET_CURRENT_DIR getcwd | 30 #define GET_CURRENT_DIR getcwd |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 #include <sys/stat.h> // To check for directory existence. | 33 #include <sys/stat.h> // To check for directory existence. |
| 33 #ifndef S_ISDIR // Not defined in stat.h on Windows. | 34 #ifndef S_ISDIR // Not defined in stat.h on Windows. |
| 34 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) | 35 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 #include <stdio.h> | 38 #include <stdio.h> |
| 38 #include <stdlib.h> | 39 #include <stdlib.h> |
| 39 #include <string.h> | 40 #include <string.h> |
| 40 | 41 |
| 41 #include <memory> | 42 #include <memory> |
| 42 | 43 |
| 44 #include "webrtc/base/checks.h" | |
| 43 #include "webrtc/typedefs.h" // For architecture defines | 45 #include "webrtc/typedefs.h" // For architecture defines |
| 44 | 46 |
| 45 namespace webrtc { | 47 namespace webrtc { |
| 46 namespace test { | 48 namespace test { |
| 47 | 49 |
| 48 #if defined(WEBRTC_IOS) | 50 #if defined(WEBRTC_IOS) |
| 49 // Defined in iosfileutils.mm. No header file to discourage use elsewhere. | 51 // Defined in iosfileutils.mm. No header file to discourage use elsewhere. |
| 50 std::string IOSOutputPath(); | 52 std::string IOSOutputPath(); |
| 51 std::string IOSRootPath(); | 53 std::string IOSRootPath(); |
| 52 std::string IOSResourcePath(std::string name, std::string extension); | 54 std::string IOSResourcePath(std::string name, std::string extension); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 } | 121 } |
| 120 | 122 |
| 121 std::string OutputPath() { | 123 std::string OutputPath() { |
| 122 return kRootDirName; | 124 return kRootDirName; |
| 123 } | 125 } |
| 124 | 126 |
| 125 std::string WorkingDir() { | 127 std::string WorkingDir() { |
| 126 return kRootDirName; | 128 return kRootDirName; |
| 127 } | 129 } |
| 128 | 130 |
| 129 #else // WEBRTC_ANDROID | 131 #else // WEBRTC_ANDROID |
| 130 | 132 |
| 131 std::string ProjectRootPath() { | 133 std::string ProjectRootPath() { |
| 132 #if defined(WEBRTC_IOS) | 134 #if defined(WEBRTC_IOS) |
| 133 return IOSRootPath(); | 135 return IOSRootPath(); |
| 134 #else | 136 #else |
| 135 std::string path = WorkingDir(); | 137 std::string path = WorkingDir(); |
| 136 if (path == kFallbackPath) { | 138 if (path == kFallbackPath) { |
| 137 return kCannotFindProjectRootDir; | 139 return kCannotFindProjectRootDir; |
| 138 } | 140 } |
| 139 if (relative_dir_path_set) { | 141 if (relative_dir_path_set) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 assert(false); | 207 assert(false); |
| 206 return ""; | 208 return ""; |
| 207 } else { | 209 } else { |
| 208 ::close(fd); | 210 ::close(fd); |
| 209 } | 211 } |
| 210 std::string ret(tempname.get()); | 212 std::string ret(tempname.get()); |
| 211 return ret; | 213 return ret; |
| 212 #endif | 214 #endif |
| 213 } | 215 } |
| 214 | 216 |
| 217 bool ReadDirectory(std::string path, std::vector<std::string>* output) { | |
| 218 RTC_DCHECK(output); | |
| 219 if (path.length() == 0 || !DirExists(path)) return false; | |
|
nisse-webrtc
2017/05/29 10:56:39
On second look, I think the DirExists check here i
AleBzk
2017/05/29 11:09:29
Done.
| |
| 220 output->clear(); | |
|
nisse-webrtc
2017/05/29 10:56:39
The comment in the header file just says that stri
AleBzk
2017/05/29 11:09:29
Done.
| |
| 221 #if defined(WEBRTC_WIN) | |
| 222 // Append separator character if needed. | |
| 223 if (path.back() != '\\') path += '\\'; | |
| 224 | |
| 225 // Init. | |
| 226 WIN32_FIND_DATA data; | |
| 227 HANDLE handle = ::FindFirstFile(rtc::ToUtf16(path + '*').c_str(), &data); | |
| 228 if (handle == INVALID_HANDLE_VALUE) return false; | |
| 229 | |
| 230 // Populate output. | |
| 231 do { | |
| 232 const std::string name = rtc::ToUtf8(data.cFileName); | |
| 233 if (name != "." && name != "..") output->emplace_back(path + name); | |
| 234 } while (::FindNextFile(handle, &data) == TRUE); | |
| 235 | |
| 236 // Release resources. | |
| 237 if (handle != INVALID_HANDLE_VALUE) ::FindClose(handle); | |
| 238 #else | |
| 239 // Append separator character if needed. | |
| 240 if (path.back() != '/') path += '/'; | |
| 241 | |
| 242 // Init. | |
| 243 DIR *dir = ::opendir(path.c_str()); | |
| 244 if (dir == nullptr) return false; | |
| 245 | |
| 246 // Populate output. | |
| 247 while (struct dirent* dirent = readdir(dir)) { | |
| 248 RTC_DCHECK(dirent); | |
|
nisse-webrtc
2017/05/29 10:56:39
A DCHECK on the loop condition right above seems u
AleBzk
2017/05/29 11:09:29
Done.
| |
| 249 const std::string& name = dirent->d_name; | |
| 250 if (name != "." && name != "..") output->emplace_back(path + name); | |
| 251 } | |
| 252 | |
| 253 // Release resources. | |
| 254 closedir(dir); | |
| 255 #endif | |
| 256 return true; | |
| 257 } | |
| 258 | |
| 215 bool CreateDir(const std::string& directory_name) { | 259 bool CreateDir(const std::string& directory_name) { |
| 216 struct stat path_info = {0}; | 260 struct stat path_info = {0}; |
| 217 // Check if the path exists already: | 261 // Check if the path exists already: |
| 218 if (stat(directory_name.c_str(), &path_info) == 0) { | 262 if (stat(directory_name.c_str(), &path_info) == 0) { |
| 219 if (!S_ISDIR(path_info.st_mode)) { | 263 if (!S_ISDIR(path_info.st_mode)) { |
| 220 fprintf(stderr, "Path %s exists but is not a directory! Remove this " | 264 fprintf(stderr, "Path %s exists but is not a directory! Remove this " |
| 221 "file and re-run to create the directory.\n", | 265 "file and re-run to create the directory.\n", |
| 222 directory_name.c_str()); | 266 directory_name.c_str()); |
| 223 return false; | 267 return false; |
| 224 } | 268 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 if (fseek(f, 0, SEEK_END) == 0) { | 344 if (fseek(f, 0, SEEK_END) == 0) { |
| 301 size = ftell(f); | 345 size = ftell(f); |
| 302 } | 346 } |
| 303 fclose(f); | 347 fclose(f); |
| 304 } | 348 } |
| 305 return size; | 349 return size; |
| 306 } | 350 } |
| 307 | 351 |
| 308 } // namespace test | 352 } // namespace test |
| 309 } // namespace webrtc | 353 } // namespace webrtc |
| OLD | NEW |