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

Side by Side Diff: sdk/lib/io/file_impl.dart

Issue 2681683005: [dart:io] Adds functions to set file access and modification time (Closed)
Patch Set: Update changelog Created 3 years, 10 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
« no previous file with comments | « sdk/lib/io/file.dart ('k') | sdk/lib/io/file_system_entity.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) 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
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
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 setLastAccessed(DateTime time) {
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 null;
408 });
409 }
410
411 external static _setLastAccessed(String path, int millis);
412
413 void setLastAccessedSync(DateTime time) {
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 }
421
383 Future<DateTime> lastModified() { 422 Future<DateTime> lastModified() {
384 return _IOService._dispatch(_FILE_LAST_MODIFIED, [path]).then((response) { 423 return _IOService._dispatch(_FILE_LAST_MODIFIED, [path]).then((response) {
385 if (_isErrorResponse(response)) { 424 if (_isErrorResponse(response)) {
386 throw _exceptionFromResponse(response, 425 throw _exceptionFromResponse(response,
387 "Cannot retrieve modification time", 426 "Cannot retrieve modification time",
388 path); 427 path);
389 } 428 }
390 return new DateTime.fromMillisecondsSinceEpoch(response); 429 return new DateTime.fromMillisecondsSinceEpoch(response);
391 }); 430 });
392 } 431 }
393 432
394 external static _lastModified(String path); 433 external static _lastModified(String path);
395 434
396 DateTime lastModifiedSync() { 435 DateTime lastModifiedSync() {
397 var ms = _lastModified(path); 436 var ms = _lastModified(path);
398 throwIfError(ms, "Cannot retrieve modification time", path); 437 throwIfError(ms, "Cannot retrieve modification time", path);
399 return new DateTime.fromMillisecondsSinceEpoch(ms); 438 return new DateTime.fromMillisecondsSinceEpoch(ms);
400 } 439 }
401 440
441 Future setLastModified(DateTime time) {
442 int millis = time.millisecondsSinceEpoch;
443 return _IOService._dispatch(_FILE_SET_LAST_MODIFIED, [path, millis])
444 .then((response) {
445 if (_isErrorResponse(response)) {
446 throw _exceptionFromResponse(response,
447 "Cannot set modification time",
448 path);
449 }
450 return null;
451 });
452 }
453
454 external static _setLastModified(String path, int millis);
455
456 void setLastModifiedSync(DateTime time) {
457 int millis = time.millisecondsSinceEpoch;
458 var result = _setLastModified(path, millis);
459 if (result is OSError) {
460 throw new FileSystemException("Failed to set file modification time",
461 path, result);
462 }
463 }
464
402 external static _open(String path, int mode); 465 external static _open(String path, int mode);
403 466
404 RandomAccessFile openSync({FileMode mode: FileMode.READ}) { 467 RandomAccessFile openSync({FileMode mode: FileMode.READ}) {
405 if (mode != FileMode.READ && 468 if (mode != FileMode.READ &&
406 mode != FileMode.WRITE && 469 mode != FileMode.WRITE &&
407 mode != FileMode.APPEND && 470 mode != FileMode.APPEND &&
408 mode != FileMode.WRITE_ONLY && 471 mode != FileMode.WRITE_ONLY &&
409 mode != FileMode.WRITE_ONLY_APPEND) { 472 mode != FileMode.WRITE_ONLY_APPEND) {
410 throw new ArgumentError('Invalid file mode for this operation'); 473 throw new ArgumentError('Invalid file mode for this operation');
411 } 474 }
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 void _checkAvailable() { 1091 void _checkAvailable() {
1029 if (_asyncDispatched) { 1092 if (_asyncDispatched) {
1030 throw new FileSystemException("An async operation is currently pending", 1093 throw new FileSystemException("An async operation is currently pending",
1031 path); 1094 path);
1032 } 1095 }
1033 if (closed) { 1096 if (closed) {
1034 throw new FileSystemException("File closed", path); 1097 throw new FileSystemException("File closed", path);
1035 } 1098 }
1036 } 1099 }
1037 } 1100 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file.dart ('k') | sdk/lib/io/file_system_entity.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698