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

Unified Diff: sdk/lib/io/directory_impl.dart

Issue 25279003: dart:io | Add Directory.CreateSystemTemp(template) and change Directory.CreateTemp(template). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add check of "TMP" environment variable if "TMPDIR" is missing. Created 7 years, 3 months 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 | « sdk/lib/io/directory.dart ('k') | sdk/lib/io/io_service.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/directory_impl.dart
diff --git a/sdk/lib/io/directory_impl.dart b/sdk/lib/io/directory_impl.dart
index ec40c3f0b04b7d0b20e1356bfac56b01760a36bf..0f81fe27c2bed12ea8465f48cc38132229464b4c 100644
--- a/sdk/lib/io/directory_impl.dart
+++ b/sdk/lib/io/directory_impl.dart
@@ -16,7 +16,7 @@ class _Directory extends FileSystemEntity implements Directory {
external static _current();
external static _setCurrent(path);
- external static _createTemp(String template);
+ external static _createTemp(String template, bool system);
external static int _exists(String path);
external static _create(String path);
external static _deleteNative(String path, bool recursive);
@@ -149,8 +149,18 @@ class _Directory extends FileSystemEntity implements Directory {
}
}
- Future<Directory> createTemp() {
- return _IOService.dispatch(_DIRECTORY_CREATE_TEMP, [path]).then((response) {
+ // TODO(13720): Make template argument mandatory on Oct 18, 2013.
+ Future<Directory> createTemp([String template]) {
+ if (path == '') {
+ if (template == null) template = '';
+ return createSystemTemp(template);
+ // TODO(13720): On Oct 18, 2013, replace this with
+ // an error. createTemp cannot be called on a Directory with empty path.
+ }
+ String fullTemplate = "$path${Platform.pathSeparator}";
+ if (template != null) fullTemplate = "$fullTemplate$template";
+ return _IOService.dispatch(_DIRECTORY_CREATE_TEMP, [fullTemplate])
+ .then((response) {
if (_isErrorResponse(response)) {
throw _exceptionOrErrorFromResponse(
response, "Creation of temporary directory failed");
@@ -159,11 +169,41 @@ class _Directory extends FileSystemEntity implements Directory {
});
}
- Directory createTempSync() {
- var result = _createTemp(path);
+ // TODO(13720): Make template argument mandatory on Oct 18, 2013.
+ Directory createTempSync([String template]) {
+ if (path == '') {
+ if (template == null) template = '';
+ return createSystemTempSync(template);
+ // TODO(13720): On Oct 18, 2013, replace this with
+ // an error. createTemp cannot be called on a Directory with empty path.
+ }
+ String fullTemplate = "$path${Platform.pathSeparator}";
+ if (template != null) fullTemplate = "$fullTemplate$template";
+ var result = _createTemp(fullTemplate, false);
+ if (result is OSError) {
+ throw new DirectoryException("Creation of temporary directory failed",
+ fullTemplate,
+ result);
+ }
+ return new Directory(result);
+ }
+
+ static Future<Directory> createSystemTemp(String template) {
+ return _IOService.dispatch(_DIRECTORY_CREATE_SYSTEM_TEMP,
+ [template]).then((response) {
+ if (response is List && response[0] != _SUCCESS_RESPONSE) {
+ throw new Directory(template)._exceptionOrErrorFromResponse(
+ response, "Creation of temporary directory failed");
+ }
+ return new Directory(response);
+ });
+ }
+
+ static Directory createSystemTempSync(String template) {
+ var result = _createTemp(template, true);
if (result is OSError) {
throw new DirectoryException("Creation of temporary directory failed",
- path,
+ template,
result);
}
return new Directory(result);
« no previous file with comments | « sdk/lib/io/directory.dart ('k') | sdk/lib/io/io_service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698