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

Side by Side Diff: runtime/bin/directory_win.cc

Issue 8588029: Add Directory.createTemp() to asynchronously create a temporary directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use snprintf. Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
Mads Ager (google) 2011/11/21 16:29:37 I don't think you need time.h now?
Bill Hesse 2011/11/22 12:49:39 Done.
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
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, int64_t number) {
243 // Returns a new, unused directory name, modifying the contents of
244 // dir_template. Creates this directory, with mode ???.
Mads Ager (google) 2011/11/21 16:29:37 Please fill in the mode part of the comments.
Bill Hesse 2011/11/22 12:49:39 Done.
245 // The return value must be freed by the caller.
246 char* path = static_cast<char*>(malloc(MAX_PATH));
247 int path_length;
248 if (0 == strncmp(const_template, "", 1)) {
249 path_length = GetTempPath(MAX_PATH, path);
250 } else {
251 snprintf(path, MAX_PATH, "%s", const_template);
252 path_length = strlen(path);
253 }
254 if (path_length > MAX_PATH - 14) {
255 path[0] = '\0';
256 return path;
257 }
258 if (path[path_length - 1] == '\\') {
259 // No base name for the directory - use "tempdir"
260 snprintf(path + path_length, MAX_PATH - path_length, "tempdir");
261 path_length = strlen(path);
262 }
263
264 int tries = 0;
265 int numeric_part = number % 1000000;
266 while (true) {
267 snprintf(path + path_length, MAX_PATH - path_length, "%.6d", numeric_part);
268 if (CreateDirectory(path, NULL)) break;
269 numeric_part++;
270 tries++;
271 if (tries > 100) {
272 path[0] = '\0';
273 break;
274 }
275 }
276 return path;
277 }
278
279
241 bool Directory::Delete(const char* dir_name) { 280 bool Directory::Delete(const char* dir_name) {
242 return (RemoveDirectory(dir_name) != 0); 281 return (RemoveDirectory(dir_name) != 0);
243 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698