Skip to content

Commit aae5159

Browse files
committed
[native_assets_builder] Lock the build directory - fixes
1 parent 4a357e0 commit aae5159

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkgs/native_assets_cli/lib/src/locking/locking.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Future<T> runUnderDirectoryLock<T>(
2525
Logger? logger,
2626
}) async {
2727
const lockFileName = '.lock';
28-
final lockFile = File.fromUri(directory.uri.resolve(lockFileName));
28+
final lockFile = _fileInDir(directory, lockFileName);
2929
return _runUnderFileLock(
3030
lockFile,
3131
callback,
@@ -34,6 +34,13 @@ Future<T> runUnderDirectoryLock<T>(
3434
);
3535
}
3636

37+
File _fileInDir(Directory path, String filename) {
38+
final dirPath = path.path;
39+
var separator = Platform.pathSeparator;
40+
if (dirPath.endsWith(separator)) separator = '';
41+
return File('$dirPath$separator$filename');
42+
}
43+
3744
/// Run [callback] with this Dart process having exclusive access to [file].
3845
///
3946
/// Note multiple isolates and isolate groups in the same Dart process share
@@ -73,6 +80,8 @@ Future<T> _runUnderFileLock<T>(
7380
);
7481
printed = true;
7582
}
83+
// Don't busy wait, give the CPU some rest.
84+
// Magic constant taken from flutter_tools for startup lock.
7685
await Future<void>.delayed(const Duration(milliseconds: 50));
7786
}
7887
}

0 commit comments

Comments
 (0)