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 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
933 external static _flush(int id); | 933 external static _flush(int id); |
934 | 934 |
935 void flushSync() { | 935 void flushSync() { |
936 _checkAvailable(); | 936 _checkAvailable(); |
937 var result = _flush(_id); | 937 var result = _flush(_id); |
938 if (result is OSError) { | 938 if (result is OSError) { |
939 throw new FileSystemException("flush failed", path, result); | 939 throw new FileSystemException("flush failed", path, result); |
940 } | 940 } |
941 } | 941 } |
942 | 942 |
943 static final int LOCK_UNLOCK = 0; | |
944 static final int LOCK_SHARED = 1; | |
945 static final int LOCK_EXCLUSIVE = 2; | |
946 | |
947 Future<RandomAccessFile> lock( | |
948 [int start, int end, FileLock mode = FileLock.EXCLUSIVE]) { | |
kustermann
2015/01/08 12:54:27
Move the enum value as first argument or make name
Søren Gjesse
2015/01/09 13:06:20
Done.
| |
949 if ((start != null && start is !int) || | |
950 (end != null && end is !int) || | |
951 mode is !FileLock) { | |
952 throw new ArgumentError(); | |
953 } | |
954 if (start == null) start = 0; | |
955 if (end == null) end = -1; | |
956 if (start == end) throw new ArgumentError(); | |
957 int lock = mode == FileLock.EXCLUSIVE ? LOCK_EXCLUSIVE : LOCK_SHARED; | |
kustermann
2015/01/08 12:54:27
Please assert always that end > start! - also furt
Søren Gjesse
2015/01/09 13:06:20
Done
| |
958 return _dispatch(_FILE_LOCK, [_id, lock, start, end]) | |
959 .then((response) { | |
960 if (_isErrorResponse(response)) { | |
961 throw _exceptionFromResponse(response, 'lock failed', path); | |
962 } | |
963 return this; | |
kustermann
2015/01/08 12:54:27
Indentation is a bit screwed up I think (also for
Søren Gjesse
2015/01/09 13:06:20
Done.
| |
964 }); | |
965 } | |
966 | |
967 Future<RandomAccessFile> unlock([int start, int end]) { | |
968 if ((start != null && start is !int) || | |
969 (end != null && end is !int)) { | |
970 throw new ArgumentError(); | |
971 } | |
972 if (start == null) start = 0; | |
973 if (end == null) end = -1; | |
974 if (start == end) throw new ArgumentError(); | |
975 return _dispatch(_FILE_LOCK, [_id, LOCK_UNLOCK, start, end]) | |
976 .then((response) { | |
977 if (_isErrorResponse(response)) { | |
978 throw _exceptionFromResponse(response, 'unlock failed', path); | |
979 } | |
980 return this; | |
981 }); | |
982 } | |
983 | |
984 external static _lock(int id, int lock, int start, int end); | |
985 | |
986 void lockSync([int start, int end, FileLock mode = FileLock.EXCLUSIVE]) { | |
987 _checkAvailable(); | |
988 if ((start != null && start is !int) || | |
989 (end != null && end is !int) || | |
990 mode is !FileLock) { | |
991 throw new ArgumentError(); | |
992 } | |
993 if (start == null) start = 0; | |
994 if (end == null) end = -1; | |
995 if (start == end) throw new ArgumentError(); | |
996 int lock = mode == FileLock.EXCLUSIVE ? LOCK_EXCLUSIVE : LOCK_SHARED; | |
997 var result = _lock(_id, lock, start, end); | |
998 if (result is OSError) { | |
999 throw new FileSystemException('lock failed', path, result); | |
1000 } | |
1001 } | |
1002 | |
1003 void unlockSync([int start, int end]) { | |
1004 _checkAvailable(); | |
1005 if ((start != null && start is !int) || | |
1006 (end != null && end is !int)) { | |
1007 throw new ArgumentError(); | |
1008 } | |
1009 if (start == null) start = 0; | |
1010 if (end == null) end = -1; | |
1011 if (start == end) throw new ArgumentError(); | |
1012 var result = _lock(_id, LOCK_UNLOCK, start, end); | |
1013 if (result is OSError) { | |
1014 throw new FileSystemException('unlock failed', path, result); | |
1015 } | |
1016 } | |
1017 | |
943 bool get closed => _id == 0; | 1018 bool get closed => _id == 0; |
944 | 1019 |
945 Future _dispatch(int request, List data, { bool markClosed: false }) { | 1020 Future _dispatch(int request, List data, { bool markClosed: false }) { |
946 if (closed) { | 1021 if (closed) { |
947 return new Future.error(new FileSystemException("File closed", path)); | 1022 return new Future.error(new FileSystemException("File closed", path)); |
948 } | 1023 } |
949 if (_asyncDispatched) { | 1024 if (_asyncDispatched) { |
950 var msg = "An async operation is currently pending"; | 1025 var msg = "An async operation is currently pending"; |
951 return new Future.error(new FileSystemException(msg, path)); | 1026 return new Future.error(new FileSystemException(msg, path)); |
952 } | 1027 } |
(...skipping 12 matching lines...) Expand all Loading... | |
965 void _checkAvailable() { | 1040 void _checkAvailable() { |
966 if (_asyncDispatched) { | 1041 if (_asyncDispatched) { |
967 throw new FileSystemException("An async operation is currently pending", | 1042 throw new FileSystemException("An async operation is currently pending", |
968 path); | 1043 path); |
969 } | 1044 } |
970 if (closed) { | 1045 if (closed) { |
971 throw new FileSystemException("File closed", path); | 1046 throw new FileSystemException("File closed", path); |
972 } | 1047 } |
973 } | 1048 } |
974 } | 1049 } |
OLD | NEW |