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

commit f3cba36f7dd88255d3a0730de472522fb6ef54ba
parent 90f29005c3d987316ca7d83ecdd7ada66dbddde1
Author: Autumn! <autumnull@posteo.net>
Date:   Sat, 29 Apr 2023 10:40:45 +0000

os: add exists()

Signed-off-by: Autumn! <autumnull@posteo.net>

Mos/os.ha | 7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git a/os/os.ha b/os/os.ha @@ -40,6 +40,13 @@ export fn readdir(path: str) ([]fs::dirent | fs::error) = fs::readdir(cwd, path) // information is returned about the link, not its target. export fn stat(path: str) (fs::filestat | fs::error) = fs::stat(cwd, path); +// Returns true if a node exists at the given path, or false if not. +// +// Note that testing for file existence before using the file can often lead to +// race conditions. If possible, prefer to simply attempt to use the file (e.g. +// via "open"), and handle the resulting error should the file not exist. +export fn exists(path: str) bool = fs::exists(cwd, path); + // Creates a directory. export fn mkdir(path: str, mode: fs::mode) (void | fs::error) = fs::mkdir(cwd, path, mode);