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

Unified 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: Avoid test failures if /tmp does not exist. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/directory_posix.cc ('k') | tests/standalone/src/DirectoryTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_win.cc
diff --git a/runtime/bin/directory_win.cc b/runtime/bin/directory_win.cc
index 0f48408adc3cc71788df0c547de0dc2c7fb1ebc4..2f85ec2687c8837a8eee0e0beb6a5383b33b29d7 100644
--- a/runtime/bin/directory_win.cc
+++ b/runtime/bin/directory_win.cc
@@ -238,6 +238,45 @@ bool Directory::Create(const char* dir_name) {
}
+char* Directory::CreateTemp(const char* const_template, int64_t number) {
+ // Returns a new, unused directory name, modifying the contents of
+ // dir_template. Creates this directory, with a default security
+ // descriptor inherited from its parent directory.
+ // The return value must be freed by the caller.
+ char* path = static_cast<char*>(malloc(MAX_PATH));
+ int path_length;
+ if (0 == strncmp(const_template, "", 1)) {
+ path_length = GetTempPath(MAX_PATH, path);
+ } else {
+ snprintf(path, MAX_PATH, "%s", const_template);
+ path_length = strlen(path);
+ }
+ if (path_length > MAX_PATH - 14) {
+ path[0] = '\0';
+ return path;
+ }
+ if (path[path_length - 1] == '\\') {
+ // No base name for the directory - use "tempdir"
+ snprintf(path + path_length, MAX_PATH - path_length, "tempdir");
+ path_length = strlen(path);
+ }
+
+ int tries = 0;
+ int numeric_part = number % 1000000;
+ while (true) {
+ snprintf(path + path_length, MAX_PATH - path_length, "%.6d", numeric_part);
+ if (CreateDirectory(path, NULL)) break;
+ numeric_part++;
+ tries++;
+ if (tries > 100) {
+ path[0] = '\0';
+ break;
+ }
+ }
+ return path;
+}
+
+
bool Directory::Delete(const char* dir_name) {
return (RemoveDirectory(dir_name) != 0);
}
« no previous file with comments | « runtime/bin/directory_posix.cc ('k') | tests/standalone/src/DirectoryTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698