Chromium Code Reviews| 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 "bin/directory.h" | 5 #include "bin/directory.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <time.h> | |
| 8 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 9 | 10 |
| 10 #include "bin/platform.h" | 11 #include "bin/platform.h" |
| 11 | 12 |
| 12 // Forward declaration. | 13 // Forward declaration. |
| 13 static bool ListRecursively(const char* dir_name, | 14 static bool ListRecursively(const char* dir_name, |
| 14 bool recursive, | 15 bool recursive, |
| 15 Dart_Port dir_port, | 16 Dart_Port dir_port, |
| 16 Dart_Port file_port, | 17 Dart_Port file_port, |
| 17 Dart_Port done_port, | 18 Dart_Port done_port, |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 return DOES_NOT_EXIST; | 232 return DOES_NOT_EXIST; |
| 232 } | 233 } |
| 233 } | 234 } |
| 234 | 235 |
| 235 | 236 |
| 236 bool Directory::Create(const char* dir_name) { | 237 bool Directory::Create(const char* dir_name) { |
| 237 return (CreateDirectory(dir_name, NULL) != 0); | 238 return (CreateDirectory(dir_name, NULL) != 0); |
| 238 } | 239 } |
| 239 | 240 |
| 240 | 241 |
| 242 char* Directory::CreateTemp(const char* const_template) { | |
|
Mads Ager (google)
2011/11/18 09:50:45
You are not using the template here. So we should
Bill Hesse
2011/11/21 15:48:41
We are using a non-empty template on both platform
| |
| 243 // Returns a new, unused directory name, modifying the contents of | |
| 244 // dir_template. Creates this directory, with mode ???. | |
| 245 // The return value must be freed by the caller. | |
| 246 char* path = static_cast<char*>(malloc(MAX_PATH)); | |
| 247 int path_length = GetTempPath(MAX_PATH, path); | |
| 248 if (path_length > MAX_PATH - 1) { | |
| 249 path[0] = '\0'; | |
|
Mads Ager (google)
2011/11/18 09:50:45
Funky indentation. Are there tabs here or somethin
Bill Hesse
2011/11/21 15:48:41
Done.
| |
| 250 return path; | |
| 251 } | |
| 252 | |
| 253 strncpy_s(path + path_length, MAX_PATH, "tempdir", 8); | |
|
Mads Ager (google)
2011/11/18 09:50:45
Use snprintf instead. That is what we have done in
| |
| 254 bool success = false; | |
| 255 int tries = 0; | |
| 256 int numeric_part = time(NULL) % 1000000; | |
|
Mads Ager (google)
2011/11/18 09:50:45
We could use UuidCreate or something to make it mo
Bill Hesse
2011/11/21 15:48:41
Using Math.Random from dart.
On 2011/11/18 09:50:
| |
| 257 while (!success && tries < 100) { | |
| 258 sprintf(path + path_length + 7, "%.6d", numeric_part); | |
|
Mads Ager (google)
2011/11/18 09:50:45
snprintf
| |
| 259 success = CreateDirectory(path, NULL); | |
| 260 if (!success) { | |
| 261 numeric_part++; | |
| 262 tries++; | |
| 263 // Return the empty string, but as a freeable array. | |
| 264 // path[0] = '\0'; | |
|
Mads Ager (google)
2011/11/18 09:50:45
Commented out code and very strange indentation.
| |
| 265 } | |
| 266 } | |
| 267 return path; | |
| 268 } | |
| 269 | |
| 270 | |
| 241 bool Directory::Delete(const char* dir_name) { | 271 bool Directory::Delete(const char* dir_name) { |
| 242 return (RemoveDirectory(dir_name) != 0); | 272 return (RemoveDirectory(dir_name) != 0); |
| 243 } | 273 } |
| OLD | NEW |