-
Notifications
You must be signed in to change notification settings - Fork 223
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
Only absolutize exe if path is a file and executable #671
base: main
Are you sure you want to change the base?
Conversation
5ec99fe
to
31eeae9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry this took me so long to get to. Approach generally looks correct
app/buck2_forkserver/src/run.rs
Outdated
@@ -353,7 +354,20 @@ pub fn maybe_absolutize_exe<'a>( | |||
|
|||
let abs = spawned_process_cwd.join(exe); | |||
if fs_util::try_exists(&abs).context("Error absolute-izing executable")? { | |||
return Ok(abs.into_path_buf().into()); | |||
let metadata = fs::metadata(&abs).context("Error getting metadata for path")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a bit of a race condition to me. Can you add fs_util::metadata_if_exists
instead and then use that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Done.
@JakobDegen has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
-- @stepancheg This seems like a reasonable alternative to me, thoughts? |
Yes, maybe it's a good idea to take a step back. The problem resolved by 37f3d25 was described like this:
As noted by @stepancheg, that is not really true, since on Unix, you run "a" found in the PATH , the binary relative to On Windows, however, a binary is first picked up from the current directory, before doing a PATH lookup, AFAIK. Since this is solving a problem specific to Windows, the fix should actually only be applied on Windows. How about never absolutize on unix, but check if the executable exists in the spawned processes' cwd and return the absolute path for that on Windows. I am just wondering though, you would have to include the file extension in the command currently, otherwise this fails right? I mean, Windows looks for various file extensions it denotes as executable (like .exe, .com, .cmd, .bat et cetera) and this would fall short if you mean to run "c/b/nix.exe" but only specify |
This part seems right to me
This depends - does window generally behave as if
This seems correct. It's possible that this means we have to re-implement a significant part of Window's command resolution. I guess it would probably be a good start if someone could properly document what it even is that Windows does here, and then we can go from there |
Hi.
I took a stab at fixing issue #670 where a path to an exe is constructed which might refer to a directory, so trying to spawn a process using that path fails with an obscure error.
Fixes #670