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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4 //
5 // Script used by the file_lock_test.dart test.
6
7 import "dart:async";
8 import "dart:io";
9
10 Future<int> testLockWholeFile(File file, int len) async {
11 var raf = await file.open(mode: APPEND);
12 await raf.setPosition(0);
13 int nextToWrite = 1;
14 while (nextToWrite <= len) {
15 await raf.lock(FileLock.BLOCKING_EXCLUSIVE, 0, len);
16
17 int at;
18 int p;
19 while (true) {
20 p = await raf.position();
21 at = await raf.readByte();
22 if (at == 0 || at == -1) break;
23 nextToWrite++;
24 }
25 await raf.setPosition(p);
26 await raf.writeByte(nextToWrite);
27 await raf.flush();
28 nextToWrite++;
29 await raf.unlock(0, len);
30 }
31
32 await raf.lock(FileLock.BLOCKING_EXCLUSIVE, 0, len);
33 await raf.setPosition(0);
34 for (int i = 1; i <= len; i++) {
35 if ((await raf.readByte()) != i) {
36 await raf.unlock(0, len);
37 await raf.close();
38 return 1;
39 }
40 }
41 await raf.unlock(0, len);
42 await raf.close();
43 return 0;
44 }
45
46 main(List<String> args) async {
47 File file = new File(args[0]);
48 int len = int.parse(args[1]);
49 exit(await testLockWholeFile(file, len));
50 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698