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

Unified Diff: sdk/lib/io/file_impl.dart

Issue 833623004: Add support for file locking (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix Windows test Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
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..b0babc24df49219b9ade531d9f0cf6a52e7b142e 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -940,6 +940,85 @@ class _RandomAccessFile
}
}
+ static final int LOCK_UNLOCK = 0;
+ static final int LOCK_SHARED = 1;
+ static final int LOCK_EXCLUSIVE = 2;
+
+ Future<RandomAccessFile> lock(
+ [FileLock mode = FileLock.EXCLUSIVE, int start = 0, int end]) {
+ 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 < 0 || end < -1 || (end != -1 && start >= end)) {
+ throw new ArgumentError();
+ }
+ int lock = mode == FileLock.EXCLUSIVE ? LOCK_EXCLUSIVE : LOCK_SHARED;
+ return _dispatch(_FILE_LOCK, [_id, lock, start, end])
+ .then((response) {
+ if (_isErrorResponse(response)) {
+ throw _exceptionFromResponse(response, 'lock failed', path);
+ }
+ return this;
+ });
+ }
+
+ Future<RandomAccessFile> unlock([int start = 0, 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([FileLock mode = FileLock.EXCLUSIVE, int start = 0, int end]) {
+ _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 < 0 || end < -1 || (end != -1 && 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 = 0, 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 }) {
« sdk/lib/io/file.dart ('K') | « sdk/lib/io/file.dart ('k') | sdk/lib/io/io_service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698