New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File opened for READ can be locked excluzive on Windows #31557

Open
sgrekhov opened this Issue Dec 6, 2017 · 0 comments

Comments

Projects
None yet
2 participants
@sgrekhov
Contributor

sgrekhov commented Dec 6, 2017

According to the RandomAccessFile,lock() or RandomAccessFile.lockSync()

To obtain an exclusive lock on a file it must be opened for writing.

But, in fact, on Windows, file opened for READ can be exclusively locked. For example, program below can be run without any issues on Windows

import "dart:io";

main() {
  File file = new File(Directory.systemTemp.path + Platform.pathSeparator + "temp1234.tmp");
  file.createSync();
  file.writeAsBytesSync(new List.filled(10, 1));
  var rf = file.openSync(mode: FileMode.READ);
  rf.lockSync(FileLock.EXCLUSIVE);
  rf.closeSync();
  file.deleteSync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment