| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:_mojo_services/mojo/files/types.mojom.dart' as types; | 5 import 'dart:_mojo_services/mojo/files/types.mojom.dart' as types; |
| 6 | 6 |
| 7 // | 7 // |
| 8 // Implementation of Directory, File, and RandomAccessFile for Mojo. | 8 // Implementation of Directory, File, and RandomAccessFile for Mojo. |
| 9 // | 9 // |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } else { | 105 } else { |
| 106 return create(); | 106 return create(); |
| 107 } | 107 } |
| 108 }); | 108 }); |
| 109 } | 109 } |
| 110 DirectoryProxy rootDirectory = await _getRootDirectory(); | 110 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 111 int flags = | 111 int flags = |
| 112 types.kOpenFlagRead | types.kOpenFlagWrite | types.kOpenFlagCreate; | 112 types.kOpenFlagRead | types.kOpenFlagWrite | types.kOpenFlagCreate; |
| 113 var response = | 113 var response = |
| 114 await rootDirectory.responseOrError( | 114 await rootDirectory.responseOrError( |
| 115 rootDirectory.ptr.openDirectory(_ensurePathIsRelative(path), | 115 rootDirectory.openDirectory(_ensurePathIsRelative(path), |
| 116 null, | 116 null, |
| 117 flags)); | 117 flags)); |
| 118 if (response.error != types.Error.ok) { | 118 if (response.error != types.Error.ok) { |
| 119 throw _OSErrorFromError(response.error); | 119 throw _OSErrorFromError(response.error); |
| 120 } | 120 } |
| 121 return this; | 121 return this; |
| 122 } | 122 } |
| 123 | 123 |
| 124 /* patch */ void createSync({bool recursive: false}) => _onSyncOperation(); | 124 /* patch */ void createSync({bool recursive: false}) => _onSyncOperation(); |
| 125 | 125 |
| 126 /* patch */ Future<Directory> createTemp([String prefix]) async { | 126 /* patch */ Future<Directory> createTemp([String prefix]) async { |
| 127 DirectoryProxy rootDirectory = await _getRootDirectory(); | 127 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 128 // Create directory and fail if it already exists. | 128 // Create directory and fail if it already exists. |
| 129 int flags = types.kOpenFlagRead | types.kOpenFlagWrite | | 129 int flags = types.kOpenFlagRead | types.kOpenFlagWrite | |
| 130 types.kOpenFlagCreate | types.kOpenFlagExclusive; | 130 types.kOpenFlagCreate | types.kOpenFlagExclusive; |
| 131 String tempPath = '$path/$prefix'; | 131 String tempPath = '$path/$prefix'; |
| 132 while (true) { | 132 while (true) { |
| 133 var response = | 133 var response = |
| 134 await rootDirectory.responseOrError( | 134 await rootDirectory.responseOrError( |
| 135 rootDirectory.ptr.openDirectory(tempPath, null, flags)); | 135 rootDirectory.openDirectory(tempPath, null, flags)); |
| 136 if (response.error == types.Error.ok) { | 136 if (response.error == types.Error.ok) { |
| 137 // Success. | 137 // Success. |
| 138 break; | 138 break; |
| 139 } | 139 } |
| 140 // Alter the path and try again. | 140 // Alter the path and try again. |
| 141 // TODO(johnmccutchan): Append a randomly generated character. | 141 // TODO(johnmccutchan): Append a randomly generated character. |
| 142 tempPath = tempPath + 'a'; | 142 tempPath = tempPath + 'a'; |
| 143 } | 143 } |
| 144 return new Directory(tempPath); | 144 return new Directory(tempPath); |
| 145 } | 145 } |
| 146 | 146 |
| 147 /* patch */ Directory createTempSync([String prefix]) => _onSyncOperation(); | 147 /* patch */ Directory createTempSync([String prefix]) => _onSyncOperation(); |
| 148 | 148 |
| 149 /* patch */ Future<bool> exists() async { | 149 /* patch */ Future<bool> exists() async { |
| 150 DirectoryProxy rootDirectory = await _getRootDirectory(); | 150 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 151 int flags = types.kOpenFlagRead | types.kOpenFlagWrite; | 151 int flags = types.kOpenFlagRead | types.kOpenFlagWrite; |
| 152 var response = | 152 var response = |
| 153 await await rootDirectory.responseOrError( | 153 await await rootDirectory.responseOrError( |
| 154 rootDirectory.ptr.openDirectory(_ensurePathIsRelative(path), | 154 rootDirectory.openDirectory(_ensurePathIsRelative(path), |
| 155 null, | 155 null, |
| 156 flags)); | 156 flags)); |
| 157 // If we can open it, it exists. | 157 // If we can open it, it exists. |
| 158 return response.error == types.Error.ok; | 158 return response.error == types.Error.ok; |
| 159 } | 159 } |
| 160 | 160 |
| 161 /* patch */ bool existsSync() => _onSyncOperation(); | 161 /* patch */ bool existsSync() => _onSyncOperation(); |
| 162 | 162 |
| 163 /* patch */ Stream<FileSystemEntity> list({bool recursive: false, | 163 /* patch */ Stream<FileSystemEntity> list({bool recursive: false, |
| 164 bool followLinks: true}) { | 164 bool followLinks: true}) { |
| 165 _DirectoryLister directoryLister = new _DirectoryLister(path, recursive); | 165 _DirectoryLister directoryLister = new _DirectoryLister(path, recursive); |
| 166 StreamController streamController = new StreamController(); | 166 StreamController streamController = new StreamController(); |
| 167 directoryLister.list(streamController); | 167 directoryLister.list(streamController); |
| 168 return streamController.stream; | 168 return streamController.stream; |
| 169 } | 169 } |
| 170 | 170 |
| 171 /* patch */ List listSync({bool recursive: false, | 171 /* patch */ List listSync({bool recursive: false, |
| 172 bool followLinks: true}) { | 172 bool followLinks: true}) { |
| 173 return _onSyncOperation(); | 173 return _onSyncOperation(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 /* patch */ Future<FileStat> stat() { | 176 /* patch */ Future<FileStat> stat() { |
| 177 return FileStat.stat(path); | 177 return FileStat.stat(path); |
| 178 } | 178 } |
| 179 | 179 |
| 180 /* patch */ FileStat statSync() => _onSyncOperation(); | 180 /* patch */ FileStat statSync() => _onSyncOperation(); |
| 181 | 181 |
| 182 /* patch */ Future<Directory> rename(String newPath) async { | 182 /* patch */ Future<Directory> rename(String newPath) async { |
| 183 DirectoryProxy rootDirectory = await _getRootDirectory(); | 183 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 184 var response = await rootDirectory.responseOrError( | 184 var response = await rootDirectory.responseOrError( |
| 185 rootDirectory.ptr.rename(_ensurePathIsRelative(path), | 185 rootDirectory.rename(_ensurePathIsRelative(path), |
| 186 _ensurePathIsRelative(newPath))); | 186 _ensurePathIsRelative(newPath))); |
| 187 if (response.error != types.Error.ok) { | 187 if (response.error != types.Error.ok) { |
| 188 throw _OSErrorFromError(response.error); | 188 throw _OSErrorFromError(response.error); |
| 189 } | 189 } |
| 190 return new Directory(newPath); | 190 return new Directory(newPath); |
| 191 } | 191 } |
| 192 | 192 |
| 193 /* patch */ Directory renameSync(String newPath) => _onSyncOperation(); | 193 /* patch */ Directory renameSync(String newPath) => _onSyncOperation(); |
| 194 | 194 |
| 195 /* patch */ static _current() { | 195 /* patch */ static _current() { |
| 196 return _currentDirectoryPath; | 196 return _currentDirectoryPath; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 DirectoryProxy rootDirectory = await _getRootDirectory(); | 243 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 244 int flags = types.kOpenFlagRead | types.kOpenFlagWrite; | 244 int flags = types.kOpenFlagRead | types.kOpenFlagWrite; |
| 245 | 245 |
| 246 while (_directoriesToList.length > 0) { | 246 while (_directoriesToList.length > 0) { |
| 247 // Remove head. | 247 // Remove head. |
| 248 String path = _directoriesToList.removeAt(0); | 248 String path = _directoriesToList.removeAt(0); |
| 249 // Open directory. | 249 // Open directory. |
| 250 DirectoryProxy directory = new DirectoryProxy.unbound(); | 250 DirectoryProxy directory = new DirectoryProxy.unbound(); |
| 251 var response = | 251 var response = |
| 252 await rootDirectory.responseOrError( | 252 await rootDirectory.responseOrError( |
| 253 rootDirectory.ptr.openDirectory(_ensurePathIsRelative(path), | 253 rootDirectory.openDirectory(_ensurePathIsRelative(path), |
| 254 directory, | 254 directory, |
| 255 flags)); | 255 flags)); |
| 256 if (response.error != types.Error.ok) { | 256 if (response.error != types.Error.ok) { |
| 257 // Skip if we can't open it. | 257 // Skip if we can't open it. |
| 258 continue; | 258 continue; |
| 259 } | 259 } |
| 260 // Read contents. | 260 // Read contents. |
| 261 var readResponse = await directory.responseOrError(directory.ptr.read()); | 261 var readResponse = await directory.responseOrError(directory.read()); |
| 262 // We are done with the directory now. | 262 // We are done with the directory now. |
| 263 directory.close(immediate: true); | 263 directory.close(immediate: true); |
| 264 if (readResponse.error != types.Error.ok) { | 264 if (readResponse.error != types.Error.ok) { |
| 265 // Skip if we can't read it. | 265 // Skip if we can't read it. |
| 266 continue; | 266 continue; |
| 267 } | 267 } |
| 268 List<types.DirectoryEntry> directoryContents = | 268 List<types.DirectoryEntry> directoryContents = |
| 269 readResponse.directoryContents; | 269 readResponse.directoryContents; |
| 270 for (types.DirectoryEntry entry in directoryContents) { | 270 for (types.DirectoryEntry entry in directoryContents) { |
| 271 String childPath = '$path/${entry.name}'; | 271 String childPath = '$path/${entry.name}'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 284 streamController.close(); | 284 streamController.close(); |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 patch class _File { | 288 patch class _File { |
| 289 /* patch */ Future<bool> exists() async { | 289 /* patch */ Future<bool> exists() async { |
| 290 DirectoryProxy rootDirectory = await _getRootDirectory(); | 290 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 291 int flags = types.kOpenFlagRead; | 291 int flags = types.kOpenFlagRead; |
| 292 var response = | 292 var response = |
| 293 await rootDirectory.responseOrError( | 293 await rootDirectory.responseOrError( |
| 294 rootDirectory.ptr.openFile(_ensurePathIsRelative(path), | 294 rootDirectory.openFile(_ensurePathIsRelative(path), |
| 295 null, | 295 null, |
| 296 flags)); | 296 flags)); |
| 297 // If we can open it, it exists. | 297 // If we can open it, it exists. |
| 298 return response.error == types.Error.ok; | 298 return response.error == types.Error.ok; |
| 299 } | 299 } |
| 300 | 300 |
| 301 /* patch */ bool existsSync() => _onSyncOperation(); | 301 /* patch */ bool existsSync() => _onSyncOperation(); |
| 302 | 302 |
| 303 /* patch */ FileStat statSync() => _onSyncOperation(); | 303 /* patch */ FileStat statSync() => _onSyncOperation(); |
| 304 | 304 |
| 305 /* patch */ Future<File> create({bool recursive: false}) async { | 305 /* patch */ Future<File> create({bool recursive: false}) async { |
| 306 if (recursive) { | 306 if (recursive) { |
| 307 // Create any parent directories. | 307 // Create any parent directories. |
| 308 await parent.create(recursive: true); | 308 await parent.create(recursive: true); |
| 309 } | 309 } |
| 310 DirectoryProxy rootDirectory = await _getRootDirectory(); | 310 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 311 int flags = types.kOpenFlagWrite | types.kOpenFlagCreate; | 311 int flags = types.kOpenFlagWrite | types.kOpenFlagCreate; |
| 312 var response = | 312 var response = |
| 313 await rootDirectory.responseOrError( | 313 await rootDirectory.responseOrError( |
| 314 rootDirectory.ptr.openFile(_ensurePathIsRelative(path), | 314 rootDirectory.openFile(_ensurePathIsRelative(path), |
| 315 null, | 315 null, |
| 316 flags)); | 316 flags)); |
| 317 if (response.error != types.Error.ok) { | 317 if (response.error != types.Error.ok) { |
| 318 throw _OSErrorFromError(response.error); | 318 throw _OSErrorFromError(response.error); |
| 319 } | 319 } |
| 320 return this; | 320 return this; |
| 321 } | 321 } |
| 322 | 322 |
| 323 /* patch */ void createSync({bool recursive: false}) => _onSyncOperation(); | 323 /* patch */ void createSync({bool recursive: false}) => _onSyncOperation(); |
| 324 | 324 |
| 325 /* patch */ Future<File> rename(String newPath) async { | 325 /* patch */ Future<File> rename(String newPath) async { |
| 326 DirectoryProxy rootDirectory = await _getRootDirectory(); | 326 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 327 var response = await rootDirectory.responseOrError( | 327 var response = await rootDirectory.responseOrError( |
| 328 rootDirectory.ptr.rename(_ensurePathIsRelative(path), | 328 rootDirectory.rename(_ensurePathIsRelative(path), |
| 329 _ensurePathIsRelative(newPath))); | 329 _ensurePathIsRelative(newPath))); |
| 330 if (response.error != types.Error.ok) { | 330 if (response.error != types.Error.ok) { |
| 331 throw _OSErrorFromError(response.error); | 331 throw _OSErrorFromError(response.error); |
| 332 } | 332 } |
| 333 return new File(newPath); | 333 return new File(newPath); |
| 334 } | 334 } |
| 335 | 335 |
| 336 /* patch */ File renameSync(String newPath) => _onSyncOperation(); | 336 /* patch */ File renameSync(String newPath) => _onSyncOperation(); |
| 337 | 337 |
| 338 /* patch */ Future<File> copy(String newPath) async { | 338 /* patch */ Future<File> copy(String newPath) async { |
| 339 File copyFile = new File(newPath); | 339 File copyFile = new File(newPath); |
| 340 Stream<List<int>> input = openRead(); | 340 Stream<List<int>> input = openRead(); |
| 341 IOSink output = copyFile.openWrite(); | 341 IOSink output = copyFile.openWrite(); |
| 342 // Copy contents. | 342 // Copy contents. |
| 343 await output.addStream(input); | 343 await output.addStream(input); |
| 344 // Close. | 344 // Close. |
| 345 await output.close(); | 345 await output.close(); |
| 346 return copyFile; | 346 return copyFile; |
| 347 } | 347 } |
| 348 | 348 |
| 349 /* patch */ File copySync(String newPath) => _onSyncOperation(); | 349 /* patch */ File copySync(String newPath) => _onSyncOperation(); |
| 350 | 350 |
| 351 /* patch */ Future<RandomAccessFile> open( | 351 /* patch */ Future<RandomAccessFile> open( |
| 352 {FileMode mode: FileMode.READ}) async { | 352 {FileMode mode: FileMode.READ}) async { |
| 353 DirectoryProxy rootDirectory = await _getRootDirectory(); | 353 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 354 FileProxy file = new FileProxy.unbound(); | 354 FileProxy file = new FileProxy.unbound(); |
| 355 var response = await rootDirectory.responseOrError( | 355 var response = await rootDirectory.responseOrError( |
| 356 rootDirectory.ptr.openFile(_ensurePathIsRelative(path), | 356 rootDirectory.openFile(_ensurePathIsRelative(path), |
| 357 file, | 357 file, |
| 358 _openFlagsFromFileMode(mode))); | 358 _openFlagsFromFileMode(mode))); |
| 359 if (response.error != types.Error.ok) { | 359 if (response.error != types.Error.ok) { |
| 360 throw _OSErrorFromError(response.error); | 360 throw _OSErrorFromError(response.error); |
| 361 } | 361 } |
| 362 // We use the raw mojo handle as our fd. | 362 // We use the raw mojo handle as our fd. |
| 363 final int fd = file.impl.endpoint.handle.h; | 363 final int fd = file.ctrl.endpoint.handle.h; |
| 364 // Construct the RandomAccessFile using the original constructor. | 364 // Construct the RandomAccessFile using the original constructor. |
| 365 _RandomAccessFile raf = new _RandomAccessFile(fd, path); | 365 _RandomAccessFile raf = new _RandomAccessFile(fd, path); |
| 366 // Hook up our proxy. | 366 // Hook up our proxy. |
| 367 raf._proxy = file; | 367 raf._proxy = file; |
| 368 return raf; | 368 return raf; |
| 369 } | 369 } |
| 370 | 370 |
| 371 /* patch */ Future<int> length() async { | 371 /* patch */ Future<int> length() async { |
| 372 FileStat fileStat = await FileStat.stat(path); | 372 FileStat fileStat = await FileStat.stat(path); |
| 373 return fileStat.size; | 373 return fileStat.size; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 /* patch */ static FileStat statSync(String path) { | 499 /* patch */ static FileStat statSync(String path) { |
| 500 return _onSyncOperation(); | 500 return _onSyncOperation(); |
| 501 } | 501 } |
| 502 | 502 |
| 503 /* patch */ static Future<FileStat> stat(String path) async { | 503 /* patch */ static Future<FileStat> stat(String path) async { |
| 504 DirectoryProxy rootDirectory = await _getRootDirectory(); | 504 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 505 int flags = types.kOpenFlagRead | types.kOpenFlagWrite; | 505 int flags = types.kOpenFlagRead | types.kOpenFlagWrite; |
| 506 DirectoryProxy directory = new DirectoryProxy.unbound(); | 506 DirectoryProxy directory = new DirectoryProxy.unbound(); |
| 507 var response = | 507 var response = |
| 508 await await rootDirectory.responseOrError( | 508 await await rootDirectory.responseOrError( |
| 509 rootDirectory.ptr.openDirectory(_ensurePathIsRelative(path), | 509 rootDirectory.openDirectory(_ensurePathIsRelative(path), |
| 510 directory, | 510 directory, |
| 511 flags)); | 511 flags)); |
| 512 if (response.error != types.Error.ok) { | 512 if (response.error != types.Error.ok) { |
| 513 throw _OSErrorFromError(response.error); | 513 throw _OSErrorFromError(response.error); |
| 514 } | 514 } |
| 515 var statResponse = await directory.responseOrError(directory.ptr.stat()); | 515 var statResponse = await directory.responseOrError(directory.stat()); |
| 516 // We are done with the directory now. | 516 // We are done with the directory now. |
| 517 directory.close(immediate: true); | 517 directory.close(immediate: true); |
| 518 if (statResponse.error != types.Error.ok) { | 518 if (statResponse.error != types.Error.ok) { |
| 519 throw _OSErrorFromError(response.error); | 519 throw _OSErrorFromError(response.error); |
| 520 } | 520 } |
| 521 types.FileInformation fileInformation = statResponse.fileInformation; | 521 types.FileInformation fileInformation = statResponse.fileInformation; |
| 522 DateTime modified = _dateTimeFromTimespec(fileInformation.mtime); | 522 DateTime modified = _dateTimeFromTimespec(fileInformation.mtime); |
| 523 DateTime accessed = _dateTimeFromTimespec(fileInformation.atime); | 523 DateTime accessed = _dateTimeFromTimespec(fileInformation.atime); |
| 524 int size = fileInformation.size; | 524 int size = fileInformation.size; |
| 525 const userReadWriteExecutableUnixMode = 0x1c0; | 525 const userReadWriteExecutableUnixMode = 0x1c0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 546 } | 546 } |
| 547 | 547 |
| 548 /* patch */ String resolveSymbolicLinksSync() { | 548 /* patch */ String resolveSymbolicLinksSync() { |
| 549 return _onSyncOperation(); | 549 return _onSyncOperation(); |
| 550 } | 550 } |
| 551 | 551 |
| 552 /* patch */ Future<FileSystemEntity> delete({bool recursive: false}) async { | 552 /* patch */ Future<FileSystemEntity> delete({bool recursive: false}) async { |
| 553 DirectoryProxy rootDirectory = await _getRootDirectory(); | 553 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 554 int flags = recursive ? types.kDeleteFlagRecursive : 0; | 554 int flags = recursive ? types.kDeleteFlagRecursive : 0; |
| 555 var response = await rootDirectory.responseOrError( | 555 var response = await rootDirectory.responseOrError( |
| 556 rootDirectory.ptr.delete(_ensurePathIsRelative(path), flags)); | 556 rootDirectory.delete(_ensurePathIsRelative(path), flags)); |
| 557 if (response.error != types.Error.ok) { | 557 if (response.error != types.Error.ok) { |
| 558 throw _OSErrorFromError(response.error); | 558 throw _OSErrorFromError(response.error); |
| 559 } | 559 } |
| 560 return this; | 560 return this; |
| 561 } | 561 } |
| 562 | 562 |
| 563 /* patch */ void deleteSync({bool recursive: false}) { | 563 /* patch */ void deleteSync({bool recursive: false}) { |
| 564 _onSyncOperation(); | 564 _onSyncOperation(); |
| 565 } | 565 } |
| 566 | 566 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 } | 641 } |
| 642 | 642 |
| 643 void _handleError(dynamic response) { | 643 void _handleError(dynamic response) { |
| 644 if (response.error != types.Error.ok) { | 644 if (response.error != types.Error.ok) { |
| 645 throw _OSErrorFromError(response.error); | 645 throw _OSErrorFromError(response.error); |
| 646 } | 646 } |
| 647 } | 647 } |
| 648 | 648 |
| 649 /* patch */ Future<RandomAccessFile> close() async { | 649 /* patch */ Future<RandomAccessFile> close() async { |
| 650 _ensureProxy(); | 650 _ensureProxy(); |
| 651 await _proxy.responseOrError(_proxy.ptr.close()); | 651 await _proxy.responseOrError(_proxy.close()); |
| 652 await _proxy.close(immediate: true); | 652 await _proxy.close(immediate: true); |
| 653 _proxy = null; | 653 _proxy = null; |
| 654 closed = true; | 654 closed = true; |
| 655 _maybePerformCleanup(); | 655 _maybePerformCleanup(); |
| 656 return this; | 656 return this; |
| 657 } | 657 } |
| 658 | 658 |
| 659 /* patch */ void closeSync() { | 659 /* patch */ void closeSync() { |
| 660 _onSyncOperation(); | 660 _onSyncOperation(); |
| 661 } | 661 } |
| 662 | 662 |
| 663 /* patch */ Future<int> readByte() async { | 663 /* patch */ Future<int> readByte() async { |
| 664 _ensureProxy(); | 664 _ensureProxy(); |
| 665 var response = await _proxy.responseOrError( | 665 var response = await _proxy.responseOrError( |
| 666 _proxy.ptr.read(1, 0, types.Whence.fromCurrent)); | 666 _proxy.read(1, 0, types.Whence.fromCurrent)); |
| 667 _handleError(response); | 667 _handleError(response); |
| 668 _resourceInfo.addRead(response.bytesRead.length); | 668 _resourceInfo.addRead(response.bytesRead.length); |
| 669 if (response.bytesRead.length == 0) { | 669 if (response.bytesRead.length == 0) { |
| 670 throw new FileSystemException("readByte failed."); | 670 throw new FileSystemException("readByte failed."); |
| 671 } | 671 } |
| 672 return response.bytesRead[0]; | 672 return response.bytesRead[0]; |
| 673 } | 673 } |
| 674 | 674 |
| 675 /* patch */ int readByteSync() { | 675 /* patch */ int readByteSync() { |
| 676 return _onSyncOperation(); | 676 return _onSyncOperation(); |
| 677 } | 677 } |
| 678 | 678 |
| 679 /* patch */ Future<List<int>> read(int bytes) async { | 679 /* patch */ Future<List<int>> read(int bytes) async { |
| 680 if (bytes is !int) { | 680 if (bytes is !int) { |
| 681 throw new ArgumentError(bytes); | 681 throw new ArgumentError(bytes); |
| 682 } | 682 } |
| 683 _ensureProxy(); | 683 _ensureProxy(); |
| 684 var response = await _proxy.responseOrError( | 684 var response = await _proxy.responseOrError( |
| 685 _proxy.ptr.read(bytes, 0, types.Whence.fromCurrent)); | 685 _proxy.read(bytes, 0, types.Whence.fromCurrent)); |
| 686 _handleError(response); | 686 _handleError(response); |
| 687 _resourceInfo.addRead(response.bytesRead.length); | 687 _resourceInfo.addRead(response.bytesRead.length); |
| 688 return response.bytesRead; | 688 return response.bytesRead; |
| 689 } | 689 } |
| 690 | 690 |
| 691 /* patch */ List<int> readSync(int bytes) { | 691 /* patch */ List<int> readSync(int bytes) { |
| 692 return _onSyncOperation(); | 692 return _onSyncOperation(); |
| 693 } | 693 } |
| 694 | 694 |
| 695 /* patch */ Future<int> readInto(List<int> buffer, | 695 /* patch */ Future<int> readInto(List<int> buffer, |
| 696 [int start = 0, int end]) async { | 696 [int start = 0, int end]) async { |
| 697 if (buffer is !List || | 697 if (buffer is !List || |
| 698 (start != null && start is !int) || | 698 (start != null && start is !int) || |
| 699 (end != null && end is !int)) { | 699 (end != null && end is !int)) { |
| 700 throw new ArgumentError(); | 700 throw new ArgumentError(); |
| 701 } | 701 } |
| 702 end = RangeError.checkValidRange(start, end, buffer.length); | 702 end = RangeError.checkValidRange(start, end, buffer.length); |
| 703 _ensureProxy(); | 703 _ensureProxy(); |
| 704 if (end == start) { | 704 if (end == start) { |
| 705 return 0; | 705 return 0; |
| 706 } | 706 } |
| 707 int length = end - start; | 707 int length = end - start; |
| 708 var response = await _proxy.responseOrError( | 708 var response = await _proxy.responseOrError( |
| 709 _proxy.ptr.read(length, 0, types.Whence.fromCurrent)); | 709 _proxy.read(length, 0, types.Whence.fromCurrent)); |
| 710 _handleError(response); | 710 _handleError(response); |
| 711 int read = response.bytesRead.length; | 711 int read = response.bytesRead.length; |
| 712 _resourceInfo.addRead(read); | 712 _resourceInfo.addRead(read); |
| 713 buffer.setRange(start, start + read, response.bytesRead); | 713 buffer.setRange(start, start + read, response.bytesRead); |
| 714 return read; | 714 return read; |
| 715 } | 715 } |
| 716 | 716 |
| 717 /* patch */ int readIntoSync(List<int> buffer, [int start = 0, int end]) { | 717 /* patch */ int readIntoSync(List<int> buffer, [int start = 0, int end]) { |
| 718 return _onSyncOperation(); | 718 return _onSyncOperation(); |
| 719 } | 719 } |
| 720 | 720 |
| 721 /* patch */ Future<RandomAccessFile> writeByte(int value) async { | 721 /* patch */ Future<RandomAccessFile> writeByte(int value) async { |
| 722 if (value is !int) { | 722 if (value is !int) { |
| 723 throw new ArgumentError(value); | 723 throw new ArgumentError(value); |
| 724 } | 724 } |
| 725 _ensureProxy(); | 725 _ensureProxy(); |
| 726 var response = await _proxy.responseOrError( | 726 var response = await _proxy.responseOrError( |
| 727 _proxy.ptr.write([value], 0, types.Whence.fromCurrent)); | 727 _proxy.write([value], 0, types.Whence.fromCurrent)); |
| 728 _handleError(response); | 728 _handleError(response); |
| 729 assert(response.numBytesWritten == 1); | 729 assert(response.numBytesWritten == 1); |
| 730 _resourceInfo.addWrite(response.numBytesWritten); | 730 _resourceInfo.addWrite(response.numBytesWritten); |
| 731 return this; | 731 return this; |
| 732 } | 732 } |
| 733 | 733 |
| 734 /* patch */ int writeByteSync(int value) { | 734 /* patch */ int writeByteSync(int value) { |
| 735 return _onSyncOperation(); | 735 return _onSyncOperation(); |
| 736 } | 736 } |
| 737 | 737 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 755 // so that the data we want to write starts at the beginning of the | 755 // so that the data we want to write starts at the beginning of the |
| 756 // buffer. | 756 // buffer. |
| 757 final buffer = new Uint8List(length); | 757 final buffer = new Uint8List(length); |
| 758 buffer.setRange(0, length, result.buffer, start); | 758 buffer.setRange(0, length, result.buffer, start); |
| 759 // Replace the buffer in result. | 759 // Replace the buffer in result. |
| 760 result.buffer = buffer; | 760 result.buffer = buffer; |
| 761 result.start = 0; | 761 result.start = 0; |
| 762 } | 762 } |
| 763 assert(result.start == 0); | 763 assert(result.start == 0); |
| 764 var response = await _proxy.responseOrError( | 764 var response = await _proxy.responseOrError( |
| 765 _proxy.ptr.write(result.buffer, 0, types.Whence.fromCurrent)); | 765 _proxy.write(result.buffer, 0, types.Whence.fromCurrent)); |
| 766 _handleError(response); | 766 _handleError(response); |
| 767 _resourceInfo.addWrite(response.numBytesWritten); | 767 _resourceInfo.addWrite(response.numBytesWritten); |
| 768 return this; | 768 return this; |
| 769 } | 769 } |
| 770 | 770 |
| 771 /* patch */ void writeFromSync(List<int> buffer, [int start = 0, int end]) { | 771 /* patch */ void writeFromSync(List<int> buffer, [int start = 0, int end]) { |
| 772 _onSyncOperation(); | 772 _onSyncOperation(); |
| 773 } | 773 } |
| 774 | 774 |
| 775 /* patch */ void writeStringSync(String string, {Encoding encoding: UTF8}) { | 775 /* patch */ void writeStringSync(String string, {Encoding encoding: UTF8}) { |
| 776 _onSyncOperation(); | 776 _onSyncOperation(); |
| 777 } | 777 } |
| 778 | 778 |
| 779 /* patch */ Future<int> position() async { | 779 /* patch */ Future<int> position() async { |
| 780 _ensureProxy(); | 780 _ensureProxy(); |
| 781 var response = await _proxy.responseOrError(_proxy.ptr.tell()); | 781 var response = await _proxy.responseOrError(_proxy.tell()); |
| 782 _handleError(response); | 782 _handleError(response); |
| 783 return response.position; | 783 return response.position; |
| 784 } | 784 } |
| 785 | 785 |
| 786 /* patch */ int positionSync() { | 786 /* patch */ int positionSync() { |
| 787 _onSyncOperation(); | 787 _onSyncOperation(); |
| 788 } | 788 } |
| 789 | 789 |
| 790 /* patch */ Future<RandomAccessFile> setPosition(int position) async { | 790 /* patch */ Future<RandomAccessFile> setPosition(int position) async { |
| 791 if (position is !int) { | 791 if (position is !int) { |
| 792 throw new ArgumentError(position); | 792 throw new ArgumentError(position); |
| 793 } | 793 } |
| 794 _ensureProxy(); | 794 _ensureProxy(); |
| 795 var response = await _proxy.responseOrError( | 795 var response = await _proxy.responseOrError( |
| 796 _proxy.ptr.seek(position, types.Whence.fromStart)); | 796 _proxy.seek(position, types.Whence.fromStart)); |
| 797 _handleError(response); | 797 _handleError(response); |
| 798 return this; | 798 return this; |
| 799 } | 799 } |
| 800 | 800 |
| 801 /* patch */ void setPositionSync(int position) { | 801 /* patch */ void setPositionSync(int position) { |
| 802 _onSyncOperation(); | 802 _onSyncOperation(); |
| 803 } | 803 } |
| 804 | 804 |
| 805 /* patch */ Future<RandomAccessFile> truncate(int length) async { | 805 /* patch */ Future<RandomAccessFile> truncate(int length) async { |
| 806 if (length is !int) { | 806 if (length is !int) { |
| 807 throw new ArgumentError(length); | 807 throw new ArgumentError(length); |
| 808 } | 808 } |
| 809 _ensureProxy(); | 809 _ensureProxy(); |
| 810 var response = await _proxy.responseOrError(_proxy.ptr.truncate(length)); | 810 var response = await _proxy.responseOrError(_proxy.truncate(length)); |
| 811 _handleError(response); | 811 _handleError(response); |
| 812 } | 812 } |
| 813 | 813 |
| 814 /* patch */ void truncateSync(int length) { | 814 /* patch */ void truncateSync(int length) { |
| 815 _onSyncOperation(); | 815 _onSyncOperation(); |
| 816 } | 816 } |
| 817 | 817 |
| 818 /* patch */ Future<int> length() async { | 818 /* patch */ Future<int> length() async { |
| 819 _ensureProxy(); | 819 _ensureProxy(); |
| 820 var response = await _proxy.responseOrError(_proxy.ptr.stat()); | 820 var response = await _proxy.responseOrError(_proxy.stat()); |
| 821 _handleError(response); | 821 _handleError(response); |
| 822 return response.fileInformation.size; | 822 return response.fileInformation.size; |
| 823 } | 823 } |
| 824 | 824 |
| 825 /* patch */ int lengthSync() { | 825 /* patch */ int lengthSync() { |
| 826 _onSyncOperation(); | 826 _onSyncOperation(); |
| 827 } | 827 } |
| 828 | 828 |
| 829 /* patch */ Future<RandomAccessFile> flush() { | 829 /* patch */ Future<RandomAccessFile> flush() { |
| 830 return this; | 830 return this; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 847 | 847 |
| 848 /* patch */ void lockSync( | 848 /* patch */ void lockSync( |
| 849 [FileLock mode = FileLock.EXCLUSIVE, int start = 0, int end]) { | 849 [FileLock mode = FileLock.EXCLUSIVE, int start = 0, int end]) { |
| 850 _onSyncOperation(); | 850 _onSyncOperation(); |
| 851 } | 851 } |
| 852 | 852 |
| 853 /* patch */ void unlockSync([int start = 0, int end]) { | 853 /* patch */ void unlockSync([int start = 0, int end]) { |
| 854 _onSyncOperation(); | 854 _onSyncOperation(); |
| 855 } | 855 } |
| 856 } | 856 } |
| OLD | NEW |