acquire method

Future<void> acquire()

Takes the exclusive single-instance lock on service.lock; the OS releases it when the process dies. Throws TomSecretsAlreadyRunning when another service (another process, or this one) holds it.

Implementation

Future<void> acquire() async {
  final key = File(lockFile).absolute.path;
  if (_held.contains(key)) throw TomSecretsAlreadyRunning(await readInfo());
  final file = await File(lockFile).open(mode: FileMode.append);
  try {
    await file.lock(FileLock.exclusive);
  } on FileSystemException {
    await file.close();
    throw TomSecretsAlreadyRunning(await readInfo());
  }
  _lock = file;
  _held.add(key);
}