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

Unified Diff: runtime/bin/directory_posix.cc

Issue 8351003: Use realpath on Linux and MacOS to compute the full path for directory listing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 months 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_posix.cc
diff --git a/runtime/bin/directory_posix.cc b/runtime/bin/directory_posix.cc
index f24371a4d3989449875340351eca1a18d6d3470e..dfcab6992445e6a24658bcf5ffc41ebc772af2c1 100644
--- a/runtime/bin/directory_posix.cc
+++ b/runtime/bin/directory_posix.cc
@@ -27,46 +27,15 @@ static bool ListRecursively(const char* dir_name,
static void ComputeFullPath(const char* dir_name,
char* path,
int* path_length) {
- size_t written = 0;
-
- if (!File::IsAbsolutePath(dir_name)) {
- ASSERT(getcwd(path, PATH_MAX) != NULL);
- *path_length = strlen(path);
- written = snprintf(path + *path_length,
- PATH_MAX - *path_length,
- "%s",
- File::PathSeparator());
- ASSERT(written == strlen(File::PathSeparator()));
- *path_length += written;
- }
-
- // Use dirname and basename to canonicalize the provided directory
- // name.
- char* dir_name_copy = strdup(dir_name);
- char* dir = dirname(dir_name_copy);
- if (strcmp(dir, ".") != 0) {
- written = snprintf(path + *path_length,
- PATH_MAX - *path_length,
- "%s%s",
- dir,
- File::PathSeparator());
- ASSERT(written == (strlen(dir) + strlen(File::PathSeparator())));
- *path_length += written;
- }
- char* base_name_copy = strdup(dir_name);
- char* base = basename(base_name_copy);
- if (strcmp(base, ".") != 0) {
- written = snprintf(path + *path_length,
- PATH_MAX - *path_length,
- "%s%s",
- base,
- File::PathSeparator());
- ASSERT(written == (strlen(base) + strlen(File::PathSeparator())));
- *path_length += written;
- }
-
- free(dir_name_copy);
- free(base_name_copy);
+ char* abs_path = realpath(dir_name, path);
+ ASSERT(abs_path != NULL);
+ *path_length = strlen(path);
+ size_t written = snprintf(path + *path_length,
+ PATH_MAX - *path_length,
+ "%s",
+ File::PathSeparator());
+ ASSERT(written == strlen(File::PathSeparator()));
+ *path_length += written;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698