-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Judge executables with API on Windows #2956
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
Conversation
d33a3ad
to
dcd3def
Compare
This PR would need to go into the |
dcd3def
to
66bfcb2
Compare
I see, thanks for pointing out @spevans |
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 would break testing at the very least - .xctest is not an executable extension but is used to execute test bundles. I'm also concerned about how it treats something as being trustworthy. Do you have additional details on that?
@compnerd You may check out: https://docs.microsoft.com/en-us/windows/win32/api/winsafer/nf-winsafer-saferiisexecutablefiletype This API comes from |
I think we should treat cases like Update: Okay, I’ve found that. The list of registered executable file extensions lies in |
66bfcb2
to
6fa7855
Compare
Latest update: I’ve searched through GitHub for all the related keywords, but none is used for discovering a The ultimate update: Managed to get identifying |
6fa7855
to
bb65125
Compare
@compnerd I've got a question now: What is this API intended for? To identify a general-meaning "executable file", or to determine whether the file can be executed through |
bb65125
to
14a17c5
Compare
On Windows, it's largely meant for checking if the file can be executed (that is, can we just give it to |
14a17c5
to
6735660
Compare
Then I think it’s ready for merge :) |
14f4441
to
de1daf4
Compare
Could it be tested somehow? Maybe against TestFoundation executable itself. |
@lxbndr - yes, TestFileManager.test_isExecutableFile should cover that case |
As expected, this regresses the test suite: https://dev.azure.com/compnerd/swift-build/_build/results?buildId=45106&view=logs&j=ec47c80d-c7cf-5f2b-7138-13cd268bea3d&t=5cfc8e20-74e6-5b9b-ff2a-9c787c40fff4 |
3af6a5a
to
cde744f
Compare
@lxbndr It’s hard to test against itself since the full path of the test suite seems hard to get ( |
2f19672
to
96cdb87
Compare
96cdb87
to
9529986
Compare
@stevapple You could try the following, it works ok on Linux so it hopefully works on Windows as well
It would be good if the test can be made the same on all platforms avoiding What does windows do for |
For |
// test unExecutable even if file has an `exe` extension | ||
try fm.copyItem(atPath: path, toPath: exePath) | ||
XCTAssertFalse(fm.isExecutableFile(atPath: exePath)) | ||
#else |
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 test could still be run on Linux where it would also pass so I would suggest removing the #if os(Windows)
and change the #else
to #if !os(Windows)
so this test is run on all platforms.
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 could run, but it’s meaningless. The two different tests actually reflect different behavior on POSIX and Windows systems, which I think should be parallel.
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.
Ideally we want to run as many of the tests across all platforms and reduce the number of platform specific tests. In this case I would suggest adding the .exe
extension to the original filename, eliminate the copy and then the 0 byte .exe
file should then pass as non-executable on all platforms.
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.
I still think merging these tests would lead to confusion, and the current tests can reflect actual cases... It's not about "running as many tests across platforms". Testing with ".exe" extension makes no sense on Linux and macOS, nor does testing POSIX permissions on Windows.
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.
I would simply add a comment above the file saying that it is intended to be seen as an not executable by windows even though it has a .exe
extension since it lacks the appropriate header, and not executable by unix since it lacks the appropriate execute bit.
Anyone to push forward this pull request? |
Ran a run on WIndows: https://dev.azure.com/compnerd/swift-build/_build/results?buildId=46028&view=results |
@swift-ci please test |
@stevapple Please squash the commits down into one commit, thanks. |
Use `GetBinaryTypeW` to identify if the file is an executable file.
Use
GetBinaryTypeW
function to judge whether a file is executable on Windows.