5 ms·
He points out a bug: julia> open(read, "/home/jakob/Documents") # yes, a directory UInt8[] I'm not sure if this is true in other languages but it is also true
by spullara 5y ago
He points out a bug:
julia> open(read, "/home/jakob/Documents") # yes, a directory
UInt8[]
I'm not sure if this is true in other languages but it is also true in Java when you attempt to read a directory as if it were a file. I ended up adding code to test if it was a directory to avoid the issue. Does this happen at a lower level?
- bitwize 5y agoIt's built into the semantics of the OS. Unix directories are ordinary files, treated specially. They can be opened and read (and written to) like any file. If you have a more primitive pager than less, you can sometimes see this by running it on a directory; you will see binary garbage with file names embedded in it, like whole pieces of corn in a turd. That said, if your HLL doesn't provide a better abstraction when reading a directory with the standard file I/O primitives, it is indeed a serious bug in the language. Don't do that, language designers and standard library authors!
- jakobnissen 5y agoIt originally threw an error in Julia, but it turned out that checking if a file is a directory is a surprisingly expensive system call, so it was removed. It seems the issue is stuck, since most people agree the current behaviour is bad, but forcing every file read to do a heavy system call is not a great solution