hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit b7f7bd08aec44cfa4174a333bd334c5ae2d8acbd
parent 4892c133c2c25bd653d753aa293f6b0d764346df
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun,  9 Jan 2022 16:36:19 +0100

os+freebsd: update fs_resolve

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mos/+freebsd/dirfdfs.ha | 40++++++----------------------------------
Mos/+linux/dirfdfs.ha | 1+
2 files changed, 7 insertions(+), 34 deletions(-)

diff --git a/os/+freebsd/dirfdfs.ha b/os/+freebsd/dirfdfs.ha @@ -333,42 +333,14 @@ fn fs_chown(fs: *fs::fs, path: str, uid: uint, gid: uint) (void | fs::error) = { }; }; -fn resolve_part(parts: *[]str, part: str) void = { - if (part == ".") { - // no-op - void; - } else if (part == "..") { - if (len(parts) != 0) { - delete(parts[len(parts) - 1]); - }; - } else { - append(parts, part); - }; -}; - fn fs_resolve(fs: *fs::fs, path: str) str = { - let parts: []str = []; - if (!path::abs(path)) { - let iter = path::iter(getcwd()); - for (true) { - match (path::next(&iter)) { - case void => - break; - case let p: str => - resolve_part(&parts, p); - }; - }; - }; - let iter = path::iter(path); - for (true) { - match (path::next(&iter)) { - case void => - break; - case let p: str => - resolve_part(&parts, p); - }; + if (path::abs(path)) { + return path; }; - return path::join(parts...); + // XXX: This approach might not be right if this fs is based on a subdir + static let buf = path::buffer { ... }; + path::set(&buf, os::getcwd(), path)!; + return path::string(&buf); }; fn fs_close(fs: *fs::fs) void = { diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -366,6 +366,7 @@ fn fs_resolve(fs: *fs::fs, path: str) str = { if (path::abs(path)) { return path; }; + // XXX: This approach might not be right if this fs is based on a subdir static let buf = path::buffer { ... }; path::set(&buf, os::getcwd(), path)!; return path::string(&buf);