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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 external static _exists(String path); | 241 external static _exists(String path); |
| 242 | 242 |
| 243 bool existsSync() { | 243 bool existsSync() { |
| 244 var result = _exists(path); | 244 var result = _exists(path); |
| 245 throwIfError(result, "Cannot check existence of file", path); | 245 throwIfError(result, "Cannot check existence of file", path); |
| 246 return result; | 246 return result; |
| 247 } | 247 } |
| 248 | 248 |
| 249 File get absolute => new File(_absolutePath); | 249 File get absolute => new File(_absolutePath); |
| 250 | 250 |
| 251 Future<FileStat> stat() => FileStat.stat(path); | |
| 252 | |
| 253 FileStat statSync() => FileStat.statSync(path); | |
| 254 | |
| 255 Future<File> create({bool recursive: false}) { | 251 Future<File> create({bool recursive: false}) { |
| 256 var result = recursive ? parent.create(recursive: true) | 252 var result = recursive ? parent.create(recursive: true) |
| 257 : new Future.value(null); | 253 : new Future.value(null); |
| 258 return result | 254 return result |
| 259 .then((_) => _IOService._dispatch(_FILE_CREATE, [path])) | 255 .then((_) => _IOService._dispatch(_FILE_CREATE, [path])) |
| 260 .then((response) { | 256 .then((response) { |
| 261 if (_isErrorResponse(response)) { | 257 if (_isErrorResponse(response)) { |
| 262 throw _exceptionFromResponse(response, "Cannot create file", path); | 258 throw _exceptionFromResponse(response, "Cannot create file", path); |
| 263 } | 259 } |
| 264 return this; | 260 return this; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 | 369 |
| 374 | 370 |
| 375 external static _lengthFromPath(String path); | 371 external static _lengthFromPath(String path); |
| 376 | 372 |
| 377 int lengthSync() { | 373 int lengthSync() { |
| 378 var result = _lengthFromPath(path); | 374 var result = _lengthFromPath(path); |
| 379 throwIfError(result, "Cannot retrieve length of file", path); | 375 throwIfError(result, "Cannot retrieve length of file", path); |
| 380 return result; | 376 return result; |
| 381 } | 377 } |
| 382 | 378 |
| 379 Future<DateTime> lastAccessed() { | |
| 380 return _IOService._dispatch(_FILE_LAST_ACCESSED, [path]).then((response) { | |
| 381 if (_isErrorResponse(response)) { | |
| 382 throw _exceptionFromResponse(response, | |
| 383 "Cannot retrieve access time", | |
| 384 path); | |
| 385 } | |
| 386 return new DateTime.fromMillisecondsSinceEpoch(response); | |
| 387 }); | |
| 388 } | |
| 389 | |
| 390 external static _lastAccessed(String path); | |
| 391 | |
| 392 DateTime lastAccessedSync() { | |
| 393 var ms = _lastAccessed(path); | |
| 394 throwIfError(ms, "Cannot retrieve access time", path); | |
| 395 return new DateTime.fromMillisecondsSinceEpoch(ms); | |
| 396 } | |
| 397 | |
| 398 Future<File> setLastAccessed(DateTime time) { | |
|
Lasse Reichstein Nielsen
2017/02/09 15:28:03
Future<File>->Future
zra
2017/02/09 17:21:39
Done.
| |
| 399 int millis = time.millisecondsSinceEpoch; | |
| 400 return _IOService._dispatch(_FILE_SET_LAST_ACCESSED, [path, millis]) | |
| 401 .then((response) { | |
| 402 if (_isErrorResponse(response)) { | |
| 403 throw _exceptionFromResponse(response, | |
| 404 "Cannot set access time", | |
| 405 path); | |
| 406 } | |
| 407 return this; | |
|
Lasse Reichstein Nielsen
2017/02/09 15:28:04
return null;
zra
2017/02/09 17:21:39
Done.
| |
| 408 }); | |
| 409 } | |
| 410 | |
| 411 external static _setLastAccessed(String path, int millis); | |
| 412 | |
| 413 File setLastAccessedSync(DateTime time) { | |
|
Lasse Reichstein Nielsen
2017/02/09 15:28:04
File->void
zra
2017/02/09 17:21:39
Done.
| |
| 414 int millis = time.millisecondsSinceEpoch; | |
| 415 var result = _setLastAccessed(path, millis); | |
| 416 if (result is OSError) { | |
| 417 throw new FileSystemException("Failed to set file access time", | |
| 418 path, result); | |
| 419 } | |
| 420 return this; | |
|
Lasse Reichstein Nielsen
2017/02/09 15:28:03
remove line.
zra
2017/02/09 17:21:39
Done.
| |
| 421 } | |
| 422 | |
| 383 Future<DateTime> lastModified() { | 423 Future<DateTime> lastModified() { |
| 384 return _IOService._dispatch(_FILE_LAST_MODIFIED, [path]).then((response) { | 424 return _IOService._dispatch(_FILE_LAST_MODIFIED, [path]).then((response) { |
| 385 if (_isErrorResponse(response)) { | 425 if (_isErrorResponse(response)) { |
| 386 throw _exceptionFromResponse(response, | 426 throw _exceptionFromResponse(response, |
| 387 "Cannot retrieve modification time", | 427 "Cannot retrieve modification time", |
| 388 path); | 428 path); |
| 389 } | 429 } |
| 390 return new DateTime.fromMillisecondsSinceEpoch(response); | 430 return new DateTime.fromMillisecondsSinceEpoch(response); |
| 391 }); | 431 }); |
| 392 } | 432 } |
| 393 | 433 |
| 394 external static _lastModified(String path); | 434 external static _lastModified(String path); |
| 395 | 435 |
| 396 DateTime lastModifiedSync() { | 436 DateTime lastModifiedSync() { |
| 397 var ms = _lastModified(path); | 437 var ms = _lastModified(path); |
| 398 throwIfError(ms, "Cannot retrieve modification time", path); | 438 throwIfError(ms, "Cannot retrieve modification time", path); |
| 399 return new DateTime.fromMillisecondsSinceEpoch(ms); | 439 return new DateTime.fromMillisecondsSinceEpoch(ms); |
| 400 } | 440 } |
| 401 | 441 |
| 442 Future<File> setLastModified(DateTime time) { | |
|
Lasse Reichstein Nielsen
2017/02/09 15:28:04
As above.
zra
2017/02/09 17:21:39
Done.
| |
| 443 int millis = time.millisecondsSinceEpoch; | |
| 444 return _IOService._dispatch(_FILE_SET_LAST_MODIFIED, [path, millis]) | |
| 445 .then((response) { | |
| 446 if (_isErrorResponse(response)) { | |
| 447 throw _exceptionFromResponse(response, | |
| 448 "Cannot set modification time", | |
| 449 path); | |
| 450 } | |
| 451 return this; | |
| 452 }); | |
| 453 } | |
| 454 | |
| 455 external static _setLastModified(String path, int millis); | |
| 456 | |
| 457 File setLastModifiedSync(DateTime time) { | |
| 458 int millis = time.millisecondsSinceEpoch; | |
| 459 var result = _setLastModified(path, millis); | |
| 460 if (result is OSError) { | |
| 461 throw new FileSystemException("Failed to set file modification time", | |
| 462 path, result); | |
| 463 } | |
| 464 return this; | |
| 465 } | |
| 466 | |
| 402 external static _open(String path, int mode); | 467 external static _open(String path, int mode); |
| 403 | 468 |
| 404 RandomAccessFile openSync({FileMode mode: FileMode.READ}) { | 469 RandomAccessFile openSync({FileMode mode: FileMode.READ}) { |
| 405 if (mode != FileMode.READ && | 470 if (mode != FileMode.READ && |
| 406 mode != FileMode.WRITE && | 471 mode != FileMode.WRITE && |
| 407 mode != FileMode.APPEND && | 472 mode != FileMode.APPEND && |
| 408 mode != FileMode.WRITE_ONLY && | 473 mode != FileMode.WRITE_ONLY && |
| 409 mode != FileMode.WRITE_ONLY_APPEND) { | 474 mode != FileMode.WRITE_ONLY_APPEND) { |
| 410 throw new ArgumentError('Invalid file mode for this operation'); | 475 throw new ArgumentError('Invalid file mode for this operation'); |
| 411 } | 476 } |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1028 void _checkAvailable() { | 1093 void _checkAvailable() { |
| 1029 if (_asyncDispatched) { | 1094 if (_asyncDispatched) { |
| 1030 throw new FileSystemException("An async operation is currently pending", | 1095 throw new FileSystemException("An async operation is currently pending", |
| 1031 path); | 1096 path); |
| 1032 } | 1097 } |
| 1033 if (closed) { | 1098 if (closed) { |
| 1034 throw new FileSystemException("File closed", path); | 1099 throw new FileSystemException("File closed", path); |
| 1035 } | 1100 } |
| 1036 } | 1101 } |
| 1037 } | 1102 } |
| OLD | NEW |