Skip to content

Commit

Permalink
Add File.executable? for Windows (#9677)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
  • Loading branch information
nof1000 and straight-shoota committed Nov 16, 2022
1 parent 002e065 commit 9f4fed0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 3 additions & 4 deletions spec/std/file_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,16 @@ describe "File" do
end
end

# TODO: implement this for win32
describe "executable?" do
pending_win32 "gives false" do
it "gives false" do
File.executable?(datapath("test_file.txt")).should be_false
end

pending_win32 "gives false when the file doesn't exist" do
it "gives false when the file doesn't exist" do
File.executable?(datapath("non_existing_file.txt")).should be_false
end

pending_win32 "gives false when a component of the path is a file" do
it "gives false when a component of the path is a file" do
File.executable?(datapath("dir", "test_file.txt", "")).should be_false
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/win32/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module Crystal::System::File
end

def self.executable?(path) : Bool
raise NotImplementedError.new("File.executable?")
LibC.GetBinaryTypeW(to_windows_path(path), out result) != 0
end

private def self.accessible?(path, mode)
Expand Down
2 changes: 2 additions & 0 deletions src/lib_c/x86_64-windows-msvc/c/winbase.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ lib LibC
MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20_u32

fun MoveFileExW(lpExistingFileName : LPWSTR, lpNewFileName : LPWSTR, dwFlags : DWORD) : BOOL

fun GetBinaryTypeW(lpApplicationName : LPWSTR, lpBinaryType : DWORD*) : BOOL
end

0 comments on commit 9f4fed0

Please sign in to comment.