Isfile and strings with "?" in 0.7.0 ... workarounds, other than try/catch?


#1

I need to test isfile on a string. However, if the string is not a filename, it will almost always include question marks. This breaks in Julia 0.7 using Windows 10 Home but not previous versions. MWE below.

v0.6.X:

julia> str = "E?Z"
"E?Z"

julia> isfile(str)
false

v.0.7.0:

julia> str = "E?Z"
"E?Z"

julia> isfile(str)
ERROR: IOError: stat: invalid argument (EINVAL)
Stacktrace:
 [1] stat(::String) at .\stat.jl:68
 [2] isfile(::String) at .\stat.jl:303
 [3] top-level scope at none:0

What changed here? Is there a clean workaround?

I know that I could enclose the test in a try/catch statement, but considering how little overhead a Boolean test should require, this seems like an extremely clumsy and unhygienic kluge.

Thanks in advance for any suggestions.


#2

Can’t reproduce on Linux:

               _                                                                                                                                                                                                                                                                
   _       _ _(_)_     |  A fresh approach to technical computing                                                                                                                                                                                                               
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org                                                                                                                                                                                                             
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.                                                                                                                                                                                                                 
  | | | | | | |/ _` |  |                                                                                                                                                                                                                                                        
  | | |_| | | | (_| |  |  Version 0.7.0 (2018-08-08 06:46 UTC)                                                                                                                                                                                                                  
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release                                                                                                                                                                                                                
|__/                   |  x86_64-pc-linux-gnu                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                
julia> str = "E?Z"
"E?Z"                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                
julia> isfile(str)
false

What OS are you using?


#3

Sorry, let me edit that into my post. Windows 10 Home.


#4

Looks like https://github.com/JuliaLang/julia/issues/26685.


#5

Right, I’m glad that it’s a known issue, but it doesn’t seem resolved yet. Looking at the comments, I see a pull request referencing it, but last comment 13 days ago and developer says “no time to fiddle with it anymore”. It’s not clear whether a I should wait for a fix, use try/catch for now, or do something else.


#6

Perhaps I should ask “is there any workaround”? I just tried the recommended “hack” workaround at https://github.com/JuliaPackaging/BinaryProvider.jl/commit/08a314a225206a68665c6f730d7c3feeda1ba615 It hung Julia 0.7 and crashed Julia 1.0 in Windows 10, even when I changed “Base.UVError” (which gave a deprecation warning in 0.7) to Base.IOError.


#7

That does seem like a bad situation. Perhaps comment on the issue to remind people in the know; maybe info from https://github.com/neovim/lua-client/issues/34 (which linked to the Julia issue and is closed) can help fix it.


#8

It seems like what is happening is that Julia is passing the string to some Windows API and that API throws an error when it encounters a question mark. If that’s indeed the case that would make this a Windows issue rather than a Julia issue.

In the meantime, this is no better than try catch I suppose, but you could also do:

function isfile_windowsisscrewingme(str::AbstractString)
    findfirst("?", str) ≡ nothing && isfile(str)
end 

#9

While the issue is Windows-specific, it seems to be a mismatch between a change in libuv and Julia’s usage of libuv that caused this, so it seems unfair to blame Windows. (note that I haven’t been a Windows user for 6 years).


#10

Thank you both for the suggestions; ExpandingMan’s suggestion is working for now. tkoolen, I’m with you on Windows; I don’t use it by choice, and never for research. Nevertheless, it has many adherents, and I’ve found that trying to convince career researchers to switch operating systems takes more effort than coding the occasional workaround…