Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Read the file in blocks of size 64k. | 7 // Read the file in blocks of size 64k. |
| 8 const int _BLOCK_SIZE = 64 * 1024; | 8 const int _BLOCK_SIZE = 64 * 1024; |
| 9 | 9 |
| 10 | 10 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 throwIfError(result, "Cannot check existence of file", path); | 237 throwIfError(result, "Cannot check existence of file", path); |
| 238 return result; | 238 return result; |
| 239 } | 239 } |
| 240 | 240 |
| 241 File get absolute => new File(_absolutePath); | 241 File get absolute => new File(_absolutePath); |
| 242 | 242 |
| 243 Future<FileStat> stat() => FileStat.stat(path); | 243 Future<FileStat> stat() => FileStat.stat(path); |
| 244 | 244 |
| 245 FileStat statSync() => FileStat.statSync(path); | 245 FileStat statSync() => FileStat.statSync(path); |
| 246 | 246 |
| 247 Future<File> create() { | 247 Future<File> create({bool recursive: false}) { |
| 248 return _IOService.dispatch(_FILE_CREATE, [path]).then((response) { | 248 return new Future.value(null) |
| 249 if (_isErrorResponse(response)) { | 249 .then((_) => recursive ? parent.exists() : true) |
|
Anders Johnsen
2013/10/30 12:23:56
Any reason to call parent.exists()? It should do i
Bill Hesse
2013/10/30 15:07:37
Done.
| |
| 250 throw _exceptionFromResponse(response, "Cannot create file", path); | 250 .then((exists) => exists ? null : parent.create(recursive: true)) |
| 251 } | 251 .then((_) => _IOService.dispatch(_FILE_CREATE, [path])) |
| 252 return this; | 252 .then((response) { |
| 253 }); | 253 if (_isErrorResponse(response)) { |
| 254 throw _exceptionFromResponse(response, "Cannot create file", path); | |
| 255 } | |
| 256 return this; | |
| 257 }); | |
| 254 } | 258 } |
| 255 | 259 |
| 256 external static _create(String path); | 260 external static _create(String path); |
| 257 | 261 |
| 258 external static _createLink(String path, String target); | 262 external static _createLink(String path, String target); |
| 259 | 263 |
| 260 external static _linkTarget(String path); | 264 external static _linkTarget(String path); |
| 261 | 265 |
| 262 void createSync() { | 266 void createSync({bool recursive: false}) { |
| 267 if (recursive && !parent.existsSync()) { | |
|
Anders Johnsen
2013/10/30 12:23:56
Ditto.
Bill Hesse
2013/10/30 15:07:37
Done.
| |
| 268 parent.createSync(recursive: true); | |
| 269 } | |
| 263 var result = _create(path); | 270 var result = _create(path); |
| 264 throwIfError(result, "Cannot create file", path); | 271 throwIfError(result, "Cannot create file", path); |
| 265 } | 272 } |
| 266 | 273 |
| 267 Future<File> _delete({bool recursive: false}) { | 274 Future<File> _delete({bool recursive: false}) { |
| 268 if (recursive) { | 275 if (recursive) { |
| 269 return new Directory(path).delete(recursive: true).then((_) => this); | 276 return new Directory(path).delete(recursive: true).then((_) => this); |
| 270 } | 277 } |
| 271 return _IOService.dispatch(_FILE_DELETE, [path]).then((response) { | 278 return _IOService.dispatch(_FILE_DELETE, [path]).then((response) { |
| 272 if (_isErrorResponse(response)) { | 279 if (_isErrorResponse(response)) { |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 | 874 |
| 868 void _checkAvailable() { | 875 void _checkAvailable() { |
| 869 if (_asyncDispatched) { | 876 if (_asyncDispatched) { |
| 870 throw new FileSystemException("An async operation is currently pending", p ath); | 877 throw new FileSystemException("An async operation is currently pending", p ath); |
| 871 } | 878 } |
| 872 if (closed) { | 879 if (closed) { |
| 873 throw new FileSystemException("File closed", path); | 880 throw new FileSystemException("File closed", path); |
| 874 } | 881 } |
| 875 } | 882 } |
| 876 } | 883 } |
| OLD | NEW |