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

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

Issue 2050413002: Adds blocking file locks. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update docs and CHANGELOG Created 4 years, 6 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 bb00477aa1d89b8d92478797d686f8196e0d20e5..5b61fb3453215d127952da6119921b8f22054a27 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -919,6 +919,18 @@ class _RandomAccessFile implements RandomAccessFile {
static final int LOCK_UNLOCK = 0;
static final int LOCK_SHARED = 1;
static final int LOCK_EXCLUSIVE = 2;
+ static final int LOCK_BLOCKING_SHARED = 3;
+ static final int LOCK_BLOCKING_EXCLUSIVE = 4;
+
+ int _fileLockValue(FileLock fl) {
+ switch (fl) {
+ case FileLock.SHARED: return LOCK_SHARED;
+ case FileLock.EXCLUSIVE: return LOCK_EXCLUSIVE;
+ case FileLock.BLOCKING_SHARED: return LOCK_BLOCKING_SHARED;
+ case FileLock.BLOCKING_EXCLUSIVE: return LOCK_BLOCKING_EXCLUSIVE;
+ default: return -1;
+ }
+ }
Future<RandomAccessFile> lock(
[FileLock mode = FileLock.EXCLUSIVE, int start = 0, int end = -1]) {
@@ -928,7 +940,7 @@ class _RandomAccessFile implements RandomAccessFile {
if ((start < 0) || (end < -1) || ((end != -1) && (start >= end))) {
throw new ArgumentError();
}
- int lock = (mode == FileLock.EXCLUSIVE) ? LOCK_EXCLUSIVE : LOCK_SHARED;
+ int lock = _fileLockValue(mode);
return _dispatch(_FILE_LOCK, [null, lock, start, end])
.then((response) {
if (_isErrorResponse(response)) {
@@ -963,7 +975,7 @@ class _RandomAccessFile implements RandomAccessFile {
if ((start < 0) || (end < -1) || ((end != -1) && (start >= end))) {
throw new ArgumentError();
}
- int lock = (mode == FileLock.EXCLUSIVE) ? LOCK_EXCLUSIVE : LOCK_SHARED;
+ int lock = _fileLockValue(mode);
var result = _ops.lock(lock, start, end);
if (result is OSError) {
throw new FileSystemException('lock failed', path, result);

Powered by Google App Engine
This is Rietveld 408576698