Index: sdk/lib/io/file_impl.dart |
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart |
index 72d5a6d2c2ed9121d796ba9b8c804c7c21629f03..6028f05c5e40d231f12d5cf84eff050470b5ce28 100644 |
--- a/sdk/lib/io/file_impl.dart |
+++ b/sdk/lib/io/file_impl.dart |
@@ -940,6 +940,81 @@ class _RandomAccessFile |
} |
} |
+ static final int LOCK_UNLOCK = 0; |
+ static final int LOCK_SHARED = 1; |
+ static final int LOCK_EXCLUSIVE = 2; |
+ |
+ Future<RandomAccessFile> lock( |
+ [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.
|
+ if ((start != null && start is !int) || |
+ (end != null && end is !int) || |
+ mode is !FileLock) { |
+ throw new ArgumentError(); |
+ } |
+ if (start == null) start = 0; |
+ if (end == null) end = -1; |
+ if (start == end) throw new ArgumentError(); |
+ 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
|
+ return _dispatch(_FILE_LOCK, [_id, lock, start, end]) |
+ .then((response) { |
+ if (_isErrorResponse(response)) { |
+ throw _exceptionFromResponse(response, 'lock failed', path); |
+ } |
+ 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.
|
+ }); |
+ } |
+ |
+ Future<RandomAccessFile> unlock([int start, int end]) { |
+ if ((start != null && start is !int) || |
+ (end != null && end is !int)) { |
+ throw new ArgumentError(); |
+ } |
+ if (start == null) start = 0; |
+ if (end == null) end = -1; |
+ if (start == end) throw new ArgumentError(); |
+ return _dispatch(_FILE_LOCK, [_id, LOCK_UNLOCK, start, end]) |
+ .then((response) { |
+ if (_isErrorResponse(response)) { |
+ throw _exceptionFromResponse(response, 'unlock failed', path); |
+ } |
+ return this; |
+ }); |
+ } |
+ |
+ external static _lock(int id, int lock, int start, int end); |
+ |
+ void lockSync([int start, int end, FileLock mode = FileLock.EXCLUSIVE]) { |
+ _checkAvailable(); |
+ if ((start != null && start is !int) || |
+ (end != null && end is !int) || |
+ mode is !FileLock) { |
+ throw new ArgumentError(); |
+ } |
+ if (start == null) start = 0; |
+ if (end == null) end = -1; |
+ if (start == end) throw new ArgumentError(); |
+ int lock = mode == FileLock.EXCLUSIVE ? LOCK_EXCLUSIVE : LOCK_SHARED; |
+ var result = _lock(_id, lock, start, end); |
+ if (result is OSError) { |
+ throw new FileSystemException('lock failed', path, result); |
+ } |
+ } |
+ |
+ void unlockSync([int start, int end]) { |
+ _checkAvailable(); |
+ if ((start != null && start is !int) || |
+ (end != null && end is !int)) { |
+ throw new ArgumentError(); |
+ } |
+ if (start == null) start = 0; |
+ if (end == null) end = -1; |
+ if (start == end) throw new ArgumentError(); |
+ var result = _lock(_id, LOCK_UNLOCK, start, end); |
+ if (result is OSError) { |
+ throw new FileSystemException('unlock failed', path, result); |
+ } |
+ } |
+ |
bool get closed => _id == 0; |
Future _dispatch(int request, List data, { bool markClosed: false }) { |