| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include <dirent.h> | 5 #include <dirent.h> |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <libgen.h> | 7 #include <libgen.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/param.h> | 9 #include <sys/param.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| 11 #include <sys/types.h> | 11 #include <sys/types.h> |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 | 13 |
| 14 #include "bin/dartutils.h" | 14 #include "bin/dartutils.h" |
| 15 #include "bin/directory.h" | 15 #include "bin/directory.h" |
| 16 #include "bin/file.h" | 16 #include "bin/file.h" |
| 17 | 17 |
| 18 // Forward declaration. | 18 // Forward declaration. |
| 19 static bool ListRecursively(const char* dir_name, | 19 static bool ListRecursively(const char* dir_name, |
| 20 bool recursive, | 20 bool recursive, |
| 21 Dart_Port dir_port, | 21 Dart_Port dir_port, |
| 22 Dart_Port file_port, | 22 Dart_Port file_port, |
| 23 Dart_Port done_port, | 23 Dart_Port done_port, |
| 24 Dart_Port error_port); | 24 Dart_Port error_port); |
| 25 | 25 |
| 26 | 26 |
| 27 static void ComputeFullPath(const char* dir_name, | 27 static void ComputeFullPath(const char* dir_name, |
| 28 char* path, | 28 char* path, |
| 29 int* path_length) { | 29 int* path_length) { |
| 30 size_t written = 0; | 30 char* abs_path = realpath(dir_name, path); |
| 31 | 31 ASSERT(abs_path != NULL); |
| 32 if (!File::IsAbsolutePath(dir_name)) { | 32 *path_length = strlen(path); |
| 33 ASSERT(getcwd(path, PATH_MAX) != NULL); | 33 size_t written = snprintf(path + *path_length, |
| 34 *path_length = strlen(path); | 34 PATH_MAX - *path_length, |
| 35 written = snprintf(path + *path_length, | 35 "%s", |
| 36 PATH_MAX - *path_length, | 36 File::PathSeparator()); |
| 37 "%s", | 37 ASSERT(written == strlen(File::PathSeparator())); |
| 38 File::PathSeparator()); | 38 *path_length += written; |
| 39 ASSERT(written == strlen(File::PathSeparator())); | |
| 40 *path_length += written; | |
| 41 } | |
| 42 | |
| 43 // Use dirname and basename to canonicalize the provided directory | |
| 44 // name. | |
| 45 char* dir_name_copy = strdup(dir_name); | |
| 46 char* dir = dirname(dir_name_copy); | |
| 47 if (strcmp(dir, ".") != 0) { | |
| 48 written = snprintf(path + *path_length, | |
| 49 PATH_MAX - *path_length, | |
| 50 "%s%s", | |
| 51 dir, | |
| 52 File::PathSeparator()); | |
| 53 ASSERT(written == (strlen(dir) + strlen(File::PathSeparator()))); | |
| 54 *path_length += written; | |
| 55 } | |
| 56 char* base_name_copy = strdup(dir_name); | |
| 57 char* base = basename(base_name_copy); | |
| 58 if (strcmp(base, ".") != 0) { | |
| 59 written = snprintf(path + *path_length, | |
| 60 PATH_MAX - *path_length, | |
| 61 "%s%s", | |
| 62 base, | |
| 63 File::PathSeparator()); | |
| 64 ASSERT(written == (strlen(base) + strlen(File::PathSeparator()))); | |
| 65 *path_length += written; | |
| 66 } | |
| 67 | |
| 68 free(dir_name_copy); | |
| 69 free(base_name_copy); | |
| 70 } | 39 } |
| 71 | 40 |
| 72 | 41 |
| 73 static bool HandleDir(char* dir_name, | 42 static bool HandleDir(char* dir_name, |
| 74 char* path, | 43 char* path, |
| 75 int path_length, | 44 int path_length, |
| 76 bool recursive, | 45 bool recursive, |
| 77 Dart_Port dir_port, | 46 Dart_Port dir_port, |
| 78 Dart_Port file_port, | 47 Dart_Port file_port, |
| 79 Dart_Port done_port, | 48 Dart_Port done_port, |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 bool Directory::Create(const char* dir_name) { | 221 bool Directory::Create(const char* dir_name) { |
| 253 // Create the directory with the permissions specified by the | 222 // Create the directory with the permissions specified by the |
| 254 // process umask. | 223 // process umask. |
| 255 return (mkdir(dir_name, 0777) == 0); | 224 return (mkdir(dir_name, 0777) == 0); |
| 256 } | 225 } |
| 257 | 226 |
| 258 | 227 |
| 259 bool Directory::Delete(const char* dir_name) { | 228 bool Directory::Delete(const char* dir_name) { |
| 260 return (rmdir(dir_name) == 0); | 229 return (rmdir(dir_name) == 0); |
| 261 } | 230 } |
| OLD | NEW |