feat: add File.realPath() to resolve symlinks and normalize paths

Implement a new static method `File.realPath(path)` that resolves the given path by traversing symlinks and removing redundant `./` and `../` components, returning the canonical absolute path. The implementation uses libuv's `uv_fs_realpath` via an asynchronous callback pattern consistent with other File operations. Includes documentation, foreign method declarations, and two error-case tests for nonexistent paths and wrong argument types.
This commit is contained in:
Bob Nystrom
2016-02-27 23:53:02 +00:00
parent 7265935df4
commit bbafbfd50a
7 changed files with 55 additions and 0 deletions
+9
View File
@@ -51,6 +51,15 @@ No encoding or decoding is done. If the file is UTF-8, then the resulting
string will be a UTF-8 string. Otherwise, it will be a string of bytes in
whatever encoding the file uses.
### File.**realPath**(path)
Resolves `path`, traversing symlinks and removining any unneeded `./` and `../`
components. Returns the canonical absolute path to the file.
:::wren
var path = "/some/./symlink/a/../b/file.txt"
System.print(File.realPath(path)) //> /real/path/a/file.txt
### File.**size**(path)
Returns the size in bytes of the contents of the file at `path`.