hare

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

commit c0d600947403bf357fd462d873e084ac1f6b920f
parent 24670548dc1cd9f7dec41369cf5256ce9dec2ec2
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date:   Thu, 18 Mar 2021 23:18:07 +0100

fs: prohibit calls to fs::mkdir with empty path

Diffstat:
Mfs/fs.ha | 7++++++-
Mfs/types.ha | 5+++++
Mfs/util.ha | 2++
3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/fs/fs.ha b/fs/fs.ha @@ -97,6 +97,9 @@ export fn mkdirs(fs: *fs, path: str) (void | error) = { // Removes a directory. The target directory must be empty; see [rmdirall] to // remove its contents as well. export fn rmdir(fs: *fs, path: str) (void | error) = { + if (path == "") { + return invalid; + }; return match (fs.rmdir) { null => io::unsupported, f: *rmdirfunc => f(fs, path), @@ -126,7 +129,9 @@ export fn rmdirall(fs: *fs, path: str) (void | error) = { }, void => break, }; - return rmdir(fs, path); + if (path != "") { + return rmdir(fs, path); + }; }; // Creates a directory and returns a subdir for it. Some filesystems support diff --git a/fs/types.ha b/fs/types.ha @@ -19,12 +19,17 @@ export type busy = void!; // For example, opening a file with [iter]. export type wrongtype = void!; +// An function was called with an invalid combination of arguments +// For example, calling [rmdir] with empty path +export type invalid = void!; + // All possible fs error types. export type error = (noentry | noaccess | exists | busy | wrongtype + | invalid | io::error)!; // File mode information. These bits do not necessarily reflect the underlying diff --git a/fs/util.ha b/fs/util.ha @@ -6,6 +6,8 @@ use strings; export fn errstr(err: error) const str = match (err) { noentry => "File or directory not found", noaccess => "Permission denied", + exists => "File or directory exists", + invalid => "Invalid argument", err: io::error => io::errstr(err), };