hare

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

commit 17b238f7f77f52c34d093fff259293f81d3b59a8
parent 4c930f9ad308c8859664382c5e78093d4f1a231f
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 26 Feb 2021 14:52:55 -0500

fs: add fs::wrongtype error

Diffstat:
Mfs/types.ha | 6+++++-
Mos/+linux/dirfdfs.ha | 7++++++-
2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/types.ha b/fs/types.ha @@ -8,8 +8,12 @@ export type noentry = void!; // The user does not have permission to use this resource. export type noaccess = void!; +// An entry of a particular type was sought, but is something else in practice. +// For example, opening a file with [iter]. +export type wrongtype = void!; + // All possible fs error types. -export type error = (noentry | noaccess | io::error)!; +export type error = (noentry | noaccess | 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 @@ -219,7 +219,12 @@ fn fs_iter(fs: *fs::fs, path: path::path) (*fs::iterator | fs::error) = { }; let fd: int = match (rt::openat2(fs.dirfd, pathbytes(path), &oh, size(rt::open_how))) { - err: rt::errno => return errno_to_io(err), + err: rt::errno => { + if (err: int == rt::ENOTDIR) { + return fs::wrongtype; + }; + return errno_to_io(err); + }, n: int => n, };