hare

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

commit f5d453989157b6a2674f77edcd78bd18e3027bc3
parent 90ae641a44f3c08879c7bf43666bc8fd13aeeba8
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  2 Mar 2021 15:06:37 -0500

fs, os::dirfdfs: add exists error type

Diffstat:
Mfs/fs.ha | 2+-
Mfs/types.ha | 5++++-
Mos/+linux/dirfdfs.ha | 5++++-
3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/fs/fs.ha b/fs/fs.ha @@ -67,7 +67,7 @@ export fn mkdirs(fs: *fs, path: path::path) (void | error) = { let parent = path::dirname(path); if (!path::equal(path, parent)) { match (mkdirs(fs, parent)) { - noaccess => void, + exists => void, err: error => return err, void => void, }; diff --git a/fs/types.ha b/fs/types.ha @@ -5,6 +5,9 @@ use path; // An entry was requested which does not exist. export type noentry = void!; +// An attempt was made to create a file or directory which already exists. +export type exists = void!; + // The user does not have permission to use this resource. export type noaccess = void!; @@ -13,7 +16,7 @@ export type noaccess = void!; export type wrongtype = void!; // All possible fs error types. -export type error = (noentry | noaccess | wrongtype | io::error)!; +export type error = (noentry | noaccess | exists | wrongtype | io::error)!; // File mode information. These bits do not necessarily reflect the underlying // operating system's mode representation, though they were chosen to be diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -189,7 +189,10 @@ fn fs_subdir(fs: *fs::fs, path: path::path) (*fs::fs | fs::error) = { fn fs_mkdir(fs: *fs::fs, path: path::path) (void | fs::error) = { let fs = fs: *os_filesystem; return match (rt::mkdirat(fs.dirfd, path, 0o755)) { - err: rt::errno => return errno_to_io(err), + err: rt::errno => switch (err) { + rt::EEXIST => fs::exists, + * => errno_to_io(err), + }, void => void, }; };