How to lock a file for writing to Dart

I would like for two programs (running on different Dart VMs) to write data to the same file (actually adding). However, I cannot find a castle or similar mechanism to avoid racing. Any suggestion? Thank.

+3
source share
2 answers

File lock has just been added. ( http://dartbug.com/17045 has been changed to fixed)

The copied example of the form https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/tests/standalone/io/file_lock_script.dart?spec=svn42733&r=42733

import "dart:io";

main(List<String> args) {
  File file = new File(args[0]);
  int start = null;
  int end = null;
  var  mode = FileLock.EXCLUSIVE;
  if (args[1] == 'SHARED') {
    mode = FileLock.SHARED;
  }
  if (args[2] != 'null') {
    start = int.parse(args[2]);
  }
  if (args[3] != 'null') {
    end = int.parse(args[3]);
  }
  var raf = file.openSync(mode: WRITE);
  try {
    raf.lockSync(mode, start, end);
    print('LOCK SUCCEEDED');
  } catch (e) {
    print('LOCK FAILED');
  } finally {
    raf.closeSync();
  }
}

. https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/tests/standalone/io/file_lock_test.dart?spec=svn42733&r=42733 .

+1

, ... , , . . . .

.

pid , ( dart: io library, pid). , pid. ( pid), . , , .

+1

All Articles