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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/directory.dart ('k') | sdk/lib/io/io_service.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of dart.io; 5 part of dart.io;
6 6
7 class _Directory extends FileSystemEntity implements Directory { 7 class _Directory extends FileSystemEntity implements Directory {
8 final String path; 8 final String path;
9 9
10 _Directory(String this.path) { 10 _Directory(String this.path) {
11 if (path is! String) { 11 if (path is! String) {
12 throw new ArgumentError('${Error.safeToString(path)} ' 12 throw new ArgumentError('${Error.safeToString(path)} '
13 'is not a String'); 13 'is not a String');
14 } 14 }
15 } 15 }
16 16
17 external static _current(); 17 external static _current();
18 external static _setCurrent(path); 18 external static _setCurrent(path);
19 external static _createTemp(String template); 19 external static _createTemp(String template, bool system);
20 external static int _exists(String path); 20 external static int _exists(String path);
21 external static _create(String path); 21 external static _create(String path);
22 external static _deleteNative(String path, bool recursive); 22 external static _deleteNative(String path, bool recursive);
23 external static _rename(String path, String newPath); 23 external static _rename(String path, String newPath);
24 external static List _list(String path, bool recursive, bool followLinks); 24 external static List _list(String path, bool recursive, bool followLinks);
25 25
26 static Directory get current { 26 static Directory get current {
27 var result = _current(); 27 var result = _current();
28 if (result is OSError) { 28 if (result is OSError) {
29 throw new DirectoryException( 29 throw new DirectoryException(
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 143
144 void createSync({bool recursive: false}) { 144 void createSync({bool recursive: false}) {
145 if (recursive) return createRecursivelySync(); 145 if (recursive) return createRecursivelySync();
146 var result = _create(path); 146 var result = _create(path);
147 if (result is OSError) { 147 if (result is OSError) {
148 throw new DirectoryException("Creation failed", path, result); 148 throw new DirectoryException("Creation failed", path, result);
149 } 149 }
150 } 150 }
151 151
152 Future<Directory> createTemp() { 152 // TODO(13720): Make template argument mandatory on Oct 18, 2013.
153 return _IOService.dispatch(_DIRECTORY_CREATE_TEMP, [path]).then((response) { 153 Future<Directory> createTemp([String template]) {
154 if (path == '') {
155 if (template == null) template = '';
156 return createSystemTemp(template);
157 // TODO(13720): On Oct 18, 2013, replace this with
158 // an error. createTemp cannot be called on a Directory with empty path.
159 }
160 String fullTemplate = "$path${Platform.pathSeparator}";
161 if (template != null) fullTemplate = "$fullTemplate$template";
162 return _IOService.dispatch(_DIRECTORY_CREATE_TEMP, [fullTemplate])
163 .then((response) {
154 if (_isErrorResponse(response)) { 164 if (_isErrorResponse(response)) {
155 throw _exceptionOrErrorFromResponse( 165 throw _exceptionOrErrorFromResponse(
156 response, "Creation of temporary directory failed"); 166 response, "Creation of temporary directory failed");
157 } 167 }
158 return new Directory(response); 168 return new Directory(response);
159 }); 169 });
160 } 170 }
161 171
162 Directory createTempSync() { 172 // TODO(13720): Make template argument mandatory on Oct 18, 2013.
163 var result = _createTemp(path); 173 Directory createTempSync([String template]) {
174 if (path == '') {
175 if (template == null) template = '';
176 return createSystemTempSync(template);
177 // TODO(13720): On Oct 18, 2013, replace this with
178 // an error. createTemp cannot be called on a Directory with empty path.
179 }
180 String fullTemplate = "$path${Platform.pathSeparator}";
181 if (template != null) fullTemplate = "$fullTemplate$template";
182 var result = _createTemp(fullTemplate, false);
164 if (result is OSError) { 183 if (result is OSError) {
165 throw new DirectoryException("Creation of temporary directory failed", 184 throw new DirectoryException("Creation of temporary directory failed",
166 path, 185 fullTemplate,
167 result); 186 result);
168 } 187 }
169 return new Directory(result); 188 return new Directory(result);
189 }
190
191 static Future<Directory> createSystemTemp(String template) {
192 return _IOService.dispatch(_DIRECTORY_CREATE_SYSTEM_TEMP,
193 [template]).then((response) {
194 if (response is List && response[0] != _SUCCESS_RESPONSE) {
195 throw new Directory(template)._exceptionOrErrorFromResponse(
196 response, "Creation of temporary directory failed");
197 }
198 return new Directory(response);
199 });
200 }
201
202 static Directory createSystemTempSync(String template) {
203 var result = _createTemp(template, true);
204 if (result is OSError) {
205 throw new DirectoryException("Creation of temporary directory failed",
206 template,
207 result);
208 }
209 return new Directory(result);
170 } 210 }
171 211
172 Future<Directory> _delete({bool recursive: false}) { 212 Future<Directory> _delete({bool recursive: false}) {
173 return _IOService.dispatch(_DIRECTORY_DELETE, [path, recursive]) 213 return _IOService.dispatch(_DIRECTORY_DELETE, [path, recursive])
174 .then((response) { 214 .then((response) {
175 if (_isErrorResponse(response)) { 215 if (_isErrorResponse(response)) {
176 throw _exceptionOrErrorFromResponse(response, "Deletion failed"); 216 throw _exceptionOrErrorFromResponse(response, "Deletion failed");
177 } 217 }
178 return this; 218 return this;
179 }); 219 });
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 controller.addError( 408 controller.addError(
369 new DirectoryException("Directory listing failed", 409 new DirectoryException("Directory listing failed",
370 errorPath, 410 errorPath,
371 err)); 411 err));
372 } else { 412 } else {
373 controller.addError( 413 controller.addError(
374 new DirectoryException("Internal error")); 414 new DirectoryException("Internal error"));
375 } 415 }
376 } 416 }
377 } 417 }
OLDNEW
« 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