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

Unified Diff: tests/standalone/io/file_blocking_lock_script.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: tests/standalone/io/file_blocking_lock_script.dart
diff --git a/tests/standalone/io/file_blocking_lock_script.dart b/tests/standalone/io/file_blocking_lock_script.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5c955c49e70959ae3ad42a74c77fa1c51421b22b
--- /dev/null
+++ b/tests/standalone/io/file_blocking_lock_script.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// Script used by the file_lock_test.dart test.
+
+import "dart:async";
+import "dart:io";
+
+Future<int> testLockWholeFile(File file, int len) async {
+ var raf = await file.open(mode: APPEND);
+ await raf.setPosition(0);
+ int nextToWrite = 1;
+ while (nextToWrite <= len) {
+ await raf.lock(FileLock.BLOCKING_EXCLUSIVE, 0, len);
+
+ int at;
+ int p;
+ while (true) {
+ p = await raf.position();
+ at = await raf.readByte();
+ if (at == 0 || at == -1) break;
+ nextToWrite++;
+ }
+ await raf.setPosition(p);
+ await raf.writeByte(nextToWrite);
+ await raf.flush();
+ nextToWrite++;
+ await raf.unlock(0, len);
+ }
+
+ await raf.lock(FileLock.BLOCKING_EXCLUSIVE, 0, len);
+ await raf.setPosition(0);
+ for (int i = 1; i <= len; i++) {
+ if ((await raf.readByte()) != i) {
+ await raf.unlock(0, len);
+ await raf.close();
+ return 1;
+ }
+ }
+ await raf.unlock(0, len);
+ await raf.close();
+ return 0;
+}
+
+main(List<String> args) async {
+ File file = new File(args[0]);
+ int len = int.parse(args[1]);
+ exit(await testLockWholeFile(file, len));
+}

Powered by Google App Engine
This is Rietveld 408576698