Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(744)

Unified Diff: webrtc/test/testsupport/fileutils.cc

Issue 2511393002: Changed the way we find the ProjectRootPath. (Closed)
Patch Set: Disable fileutils unittest in Windows. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/test/testsupport/fileutils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/test/testsupport/fileutils.cc
diff --git a/webrtc/test/testsupport/fileutils.cc b/webrtc/test/testsupport/fileutils.cc
index fb66a1a95d1fb0709f4e78e8d9a46443c21c6f58..97d58eba60f2835e348a0a9f8413ddb248a6ec69 100644
--- a/webrtc/test/testsupport/fileutils.cc
+++ b/webrtc/test/testsupport/fileutils.cc
@@ -18,6 +18,8 @@
#include <windows.h>
#include <algorithm>
+#include "Shlwapi.h"
+
#include "webrtc/system_wrappers/include/utf_util_win.h"
#define GET_CURRENT_DIR _getcwd
#else
@@ -127,24 +129,23 @@ std::string ProjectRootPath() {
if (path == kFallbackPath) {
return kCannotFindProjectRootDir;
}
- if (relative_dir_path_set && strcmp(relative_dir_path, ".") != 0) {
+ if (relative_dir_path_set) {
path = path + kPathDelimiter + relative_dir_path;
}
- // Remove two directory levels from the path, i.e. a path like
- // /absolute/path/src/out/Debug will become /absolute/path/src/
- size_t path_delimiter_index = path.find_last_of(kPathDelimiter);
- if (path_delimiter_index != std::string::npos) {
- // Move up one directory in the directory tree.
- path = path.substr(0, path_delimiter_index);
- path_delimiter_index = path.find_last_of(kPathDelimiter);
- if (path_delimiter_index != std::string::npos) {
- // Move up another directory in the directory tree. We should now be at
- // the project root.
- return path.substr(0, path_delimiter_index) + kPathDelimiter;
- }
+ path = path + kPathDelimiter + ".." + kPathDelimiter + "..";
+ char canonical_path[FILENAME_MAX];
+#ifdef WIN32
+ bool succeeded = PathCanonicalizeA(canonical_path, path.c_str());
+#else
+ bool succeeded = realpath(path.c_str(), canonical_path) != NULL;
+#endif
+ if (succeeded) {
+ path = std::string(canonical_path) + kPathDelimiter;
+ return path;
+ } else {
+ fprintf(stderr, "Cannot find project root directory!\n");
+ return kCannotFindProjectRootDir;
}
- fprintf(stderr, "Cannot find project root directory!\n");
- return kCannotFindProjectRootDir;
#endif
}
« no previous file with comments | « no previous file | webrtc/test/testsupport/fileutils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698