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

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

Issue 25720002: Add Directory.systemTemp getter to replace createSystemTemp(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't add an extra / to a directory ending in // Created 7 years, 2 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 ac048de8887557c774eb7815f9c9eeab6341dbf5..288364868df2b194827bd594a157b9ecb1755f04 100644
--- a/sdk/lib/io/directory_impl.dart
+++ b/sdk/lib/io/directory_impl.dart
@@ -16,7 +16,8 @@ class _Directory extends FileSystemEntity implements Directory {
external static _current();
external static _setCurrent(path);
- external static _createTemp(String template, bool system);
+ external static _createTemp(String path);
+ external static String _systemTemp();
external static int _exists(String path);
external static _create(String path);
external static _deleteNative(String path, bool recursive);
@@ -149,17 +150,22 @@ class _Directory extends FileSystemEntity implements Directory {
}
}
- // TODO(13720): Make template argument mandatory on Oct 18, 2013.
- Future<Directory> createTemp([String template]) {
+ static Directory get systemTemp => new Directory(_systemTemp());
+
+ Future<Directory> createTemp([String prefix]) {
+ if (prefix == null) prefix = '';
if (path == '') {
- if (template == null) template = '';
- return createSystemTemp(template);
+ return systemTemp.createTemp(prefix);
// 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])
+ String fullPrefix;
+ if (path.endsWith('/') || (Platform.isWindows && path.endsWith('\\'))) {
+ fullPrefix = "$path$prefix";
+ } else {
+ fullPrefix = "$path${Platform.pathSeparator}$prefix";
+ }
+ return _IOService.dispatch(_DIRECTORY_CREATE_TEMP, [fullPrefix])
.then((response) {
if (_isErrorResponse(response)) {
throw _exceptionOrErrorFromResponse(
@@ -169,41 +175,23 @@ class _Directory extends FileSystemEntity implements Directory {
});
}
- // TODO(13720): Make template argument mandatory on Oct 18, 2013.
- Directory createTempSync([String template]) {
+ Directory createTempSync([String prefix]) {
+ if (prefix == null) prefix = '';
if (path == '') {
- if (template == null) template = '';
- return createSystemTempSync(template);
+ return systemTemp.createTempSync(prefix);
// 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);
+ String fullPrefix;
+ if (path.endsWith('/') || (Platform.isWindows && path.endsWith('\\'))) {
+ fullPrefix = "$path$prefix";
+ } else {
+ fullPrefix = "$path${Platform.pathSeparator}$prefix";
}
- 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);
+ var result = _createTemp(fullPrefix);
if (result is OSError) {
throw new DirectoryException("Creation of temporary directory failed",
- template,
+ fullPrefix,
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