| Index: runtime/bin/file_impl.dart
|
| diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
|
| index d19f34484a43768798ef52507813aa3c84f72e90..fa6b971460e3761278c016fbfdb3501f42288d82 100644
|
| --- a/runtime/bin/file_impl.dart
|
| +++ b/runtime/bin/file_impl.dart
|
| @@ -336,6 +336,17 @@ class _CreateOperation extends _FileOperation {
|
| }
|
|
|
|
|
| +class _DeleteOperation extends _FileOperation {
|
| + _DeleteOperation(String this._name);
|
| +
|
| + void execute(ReceivePort port) {
|
| + _replyPort.send(_File._checkedDelete(_name), port.toSendPort());
|
| + }
|
| +
|
| + String _name;
|
| +}
|
| +
|
| +
|
| class _ExitOperation extends _FileOperation {
|
| void execute(ReceivePort port) {
|
| port.close();
|
| @@ -428,6 +439,7 @@ class _File implements File {
|
| static int _length(int id) native "File_Length";
|
| static int _flush(int id) native "File_Flush";
|
| static bool _create(String name) native "File_Create";
|
| + static bool _delete(String name) native "File_Delete";
|
| static String _fullPath(String name) native "File_FullPath";
|
|
|
| static int _checkReadWriteListArguments(int length, int offset, int bytes) {
|
| @@ -447,6 +459,11 @@ class _File implements File {
|
| return _create(name);
|
| }
|
|
|
| + static bool _checkedDelete(String name) {
|
| + if (name is !String) return false;
|
| + return _delete(name);
|
| + }
|
| +
|
| static int _checkedWriteString(int id, String string) {
|
| if (string is !String) return -1;
|
| return _writeString(id, string);
|
| @@ -507,6 +524,31 @@ class _File implements File {
|
| }
|
| }
|
|
|
| + void delete() {
|
| + _asyncUsed = true;
|
| + var handler = (_deleteHandler != null) ? _deleteHandler : () => null;
|
| + var handleDeleteResult = (created, ignored) {
|
| + if (created) {
|
| + handler();
|
| + } else if (_errorHandler != null) {
|
| + _errorHandler("Cannot delete file: $_name");
|
| + }
|
| + };
|
| + var operation = new _DeleteOperation(_name);
|
| + _scheduler.enqueue(operation, handleDeleteResult);
|
| + }
|
| +
|
| + void deleteSync() {
|
| + if (_asyncUsed) {
|
| + throw new FileIOException(
|
| + "Mixed use of synchronous and asynchronous API");
|
| + }
|
| + bool deleted = _checkedDelete(_name);
|
| + if (!deleted) {
|
| + throw new FileIOException("Cannot delete file: $_name");
|
| + }
|
| + }
|
| +
|
| void open([bool writable = false]) {
|
| _asyncUsed = true;
|
| var handler = (_openHandler != null) ? _openHandler : () => null;
|
| @@ -897,6 +939,10 @@ class _File implements File {
|
| _createHandler = handler;
|
| }
|
|
|
| + void set deleteHandler(void handler()) {
|
| + _deleteHandler = handler;
|
| + }
|
| +
|
| void set openHandler(void handler()) {
|
| _openHandler = handler;
|
| }
|
| @@ -949,6 +995,7 @@ class _File implements File {
|
|
|
| var _existsHandler;
|
| var _createHandler;
|
| + var _deleteHandler;
|
| var _openHandler;
|
| var _closeHandler;
|
| var _readByteHandler;
|
|
|