crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.42k stars 1.62k forks source link

`File.info?` on a directory path to file breaks on Windows #15073

Open HertzDevil opened 1 week ago

HertzDevil commented 1 week ago

If README.md is a file in the current directory, then this raises an exception:

File.info?("README.md/")
Unhandled exception: Unable to get file info: 'README.md/': The directory name is invalid. (File::Error)
  from src\crystal\system\win32\file.cr:126 in 'check_not_found_error'
  from src\crystal\system\win32\file.cr:169 in 'info?'
  from src\file.cr:198 in 'info?'
  from src\file.cr:197 in 'info?'
  from usr\test.cr:132 in '__crystal_main'
  from src\crystal\main.cr:118 in 'main_user_code'
  from src\crystal\main.cr:104 in 'main'
  from src\crystal\main.cr:130 in 'main'
  from src\crystal\system\win32\wmain.cr:37 in 'wmain'
  from D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 in '__scrt_common_main_seh'
  from C:\WINDOWS\System32\KERNEL32.DLL +187367 in 'BaseThreadInitThunk'
  from C:\WINDOWS\SYSTEM32\ntdll.dll +547436 in 'RtlUserThreadStart'

It is raised here:

https://github.com/crystal-lang/crystal/blob/dacd97bccc80b41c7d6c448cfad19d37184766e9/src/crystal/system/win32/file.cr#L115-L128

The error message suggests a WinError.value of ERROR_DIRECTORY, which does not count as an expected failure. I have definitely never seen this before, and I am sure our Windows CI would have caught it, but I also recently upgraded to Windows 24H2 (10.0.26100.1742). Could anyone else confirm this?

straight-shoota commented 1 week ago

On 23H2 build 22631.4317 File.info?("README.md/") returns nil. So it seems to be a new error message.

For reference, this is the error message for Get-Content README.md/:

Get-Content : Cannot find path 'C:\crystal\crystal\README.md\' because it does not exist.
At line:4 char:1
+ Get-Content README.md/
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\crystal\crystal\README.md\:String) [Get-Content], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
HertzDevil commented 1 week ago

On Wine I found something probably related to this: https://gitlab.winehq.org/wine/wine/-/merge_requests/5737