You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While SytemFileSystem.resolve is documented as throwing FileNotFoundException this behaviour seems unnecessary for the stated goal of resolving an absolute path.
Behaviour is inconsistent with java.io.File.absolutePath (and canonicalPath), neither of which fail on a non-existing file.
There doesn't appear to be any other mechanism to get an absolute path from a Path.
Proposing that SytemFileSystem.resolve does not throw FileNotFoundException, instead leaving it to consumers of the Path to handle existence in the context of using that path.
The text was updated successfully, but these errors were encountered:
There are three distinct operations on a file path:
canonicalization / normalization: remove all unnecessary (or trivially resolvable) .. and ., remove trailing path separator, etc. (that's what j.i.File::canonicalPath and j.n.f.Path::normalize do)
convert a relative path to an absolute path (that's what j.i.File::absolutePath and j.n.f.Path::toAbsolutePath do)
and finally, there's a real path resolution (j.n.f.Path::toRealPath, k.i.f.FileSystem::resolve) that does both previous operations and also resolves symbolic links along the way.
First two operations are abstract and work with a path that might point to a nonexistent file.
But the last one works only with path that actually points somewhere.
So there's nothing wrong with FNFE being thrown from resolve. The problem is missing normalization function (#223) and toAbstractPath analogue.
internal val Path.absolutePath: Path
get() = File(this.toString()).canonicalFile.asPath()
internal fun File.asPath(): Path = Path(this.toString())
fzhinkin
changed the title
SystemFileSystem.resolve throws FileNotFoundException
FileSystem: missing a function to construct an absolute path from a relative one
Sep 4, 2024
While
SytemFileSystem.resolve
is documented as throwing FileNotFoundException this behaviour seems unnecessary for the stated goal of resolving an absolute path.Behaviour is inconsistent with
java.io.File.absolutePath
(andcanonicalPath
), neither of which fail on a non-existing file.There doesn't appear to be any other mechanism to get an absolute path from a
Path
.Proposing that
SytemFileSystem.resolve
does not throwFileNotFoundException
, instead leaving it to consumers of the Path to handle existence in the context of using that path.The text was updated successfully, but these errors were encountered: