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

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: Added Windows code. 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
« runtime/bin/directory_posix.cc ('K') | « runtime/bin/directory_posix.cc ('k') | no next file » | 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..ae905c01decee344753032b7270660057f6cc599 100644
--- a/runtime/bin/directory_win.cc
+++ b/runtime/bin/directory_win.cc
@@ -5,6 +5,7 @@
#include "bin/directory.h"
#include <errno.h>
+#include <time.h>
#include <sys/stat.h>
#include "bin/platform.h"
@@ -238,6 +239,35 @@ bool Directory::Create(const char* dir_name) {
}
+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
+ // Returns a new, unused directory name, modifying the contents of
+ // dir_template. Creates this directory, with mode ???.
+ // The return value must be freed by the caller.
+ char* path = static_cast<char*>(malloc(MAX_PATH));
+ int path_length = GetTempPath(MAX_PATH, path);
+ if (path_length > MAX_PATH - 1) {
+ 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.
+ return path;
+ }
+
+ 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
+ bool success = false;
+ int tries = 0;
+ 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:
+ while (!success && tries < 100) {
+ sprintf(path + path_length + 7, "%.6d", numeric_part);
Mads Ager (google) 2011/11/18 09:50:45 snprintf
+ success = CreateDirectory(path, NULL);
+ if (!success) {
+ numeric_part++;
+ tries++;
+ // Return the empty string, but as a freeable array.
+ // path[0] = '\0';
Mads Ager (google) 2011/11/18 09:50:45 Commented out code and very strange indentation.
+ }
+ }
+ return path;
+}
+
+
bool Directory::Delete(const char* dir_name) {
return (RemoveDirectory(dir_name) != 0);
}
« runtime/bin/directory_posix.cc ('K') | « runtime/bin/directory_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698