From 36815b54da278b006a07cd9c7bf9566238a0568d Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Tue, 2 May 2023 15:48:42 +0800 Subject: [PATCH] Fix `File.info(File::NULL)` on Windows --- spec/std/file_spec.cr | 3 +-- src/crystal/system/win32/file.cr | 6 +----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/spec/std/file_spec.cr b/spec/std/file_spec.cr index 7edabb6a390d..190b718e217c 100644 --- a/spec/std/file_spec.cr +++ b/spec/std/file_spec.cr @@ -428,8 +428,7 @@ describe "File" do info.type.should eq(File::Type::Directory) end - # TODO: support stating nul on windows - pending_win32 "gets for a character device" do + it "gets for a character device" do info = File.info(File::NULL) info.type.should eq(File::Type::CharacterDevice) end diff --git a/src/crystal/system/win32/file.cr b/src/crystal/system/win32/file.cr index 145ac11f7aa3..21930501eaf7 100644 --- a/src/crystal/system/win32/file.cr +++ b/src/crystal/system/win32/file.cr @@ -164,11 +164,7 @@ module Crystal::System::File return check_not_found_error("Unable to get file info", path) if handle == LibC::INVALID_HANDLE_VALUE begin - if LibC.GetFileInformationByHandle(handle, out file_info) == 0 - raise ::File::Error.from_winerror("Unable to get file info", file: path) - end - - ::File::Info.new(file_info, LibC::FILE_TYPE_DISK) + FileDescriptor.system_info(handle) ensure LibC.CloseHandle(handle) end