Skip to content

Create binstubs atomically. #4216

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

Closed
sigurdm opened this issue Apr 11, 2024 · 1 comment
Closed

Create binstubs atomically. #4216

sigurdm opened this issue Apr 11, 2024 · 1 comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sigurdm
Copy link
Contributor

sigurdm commented Apr 11, 2024

Currently we write the binstub, and chmod it to be executable. There is a race here with concurrent invocations. (see flutter/flutter#144408)

Instead we could write it to a temp-location, chmod it and move it to PUB_CACHE/bin atomically.

@sigurdm sigurdm added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Apr 11, 2024
@sigurdm
Copy link
Contributor Author

sigurdm commented Apr 11, 2024

Seems we already do this.

try {
final tmpPath = p.join(tempDir, binStubPath);
// Write this as the system encoding since the system is going to
// execute it and it might contain non-ASCII characters in the
// path names.
writeTextFile(tmpPath, binstub, encoding: const SystemEncoding());
if (Platform.isLinux || Platform.isMacOS) {
// Make it executable.
var result = Process.runSync('chmod', ['+x', tmpPath]);
if (result.exitCode != 0) {
// Couldn't make it executable so don't leave it laying around.
fail('Could not make "$tmpPath" executable (exit code '
'${result.exitCode}):\n${result.stderr}');
}
}
File(tmpPath).renameSync(binStubPath);
} finally {
deleteEntry(tempDir);
}

Was done in #3285

@sigurdm sigurdm closed this as completed Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

1 participant