commit 1ab4dc3f284daf20f890fc10e5ce06045b7bfa84
parent 46b01f5413a773c17978b0c0399dd6732b3c24ce
Author: Drew DeVault <sir@cmpwn.com>
Date: Thu, 4 Nov 2021 14:43:47 +0100
hare::module: permit empty modules with README
This addresses a haredoc issue for meta-modules. We might have to adjust
our approach for this later if this causes problems.
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/fs/fs.ha b/fs/fs.ha
@@ -140,6 +140,20 @@ export fn stat(fs: *fs, path: str) (filestat | error) = {
};
};
+// 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(fs: *fs, path: str) bool = {
+ match (stat(fs, path)) {
+ case filestat =>
+ return true;
+ case error =>
+ return false;
+ };
+};
+
// Returns the path referred to by a symbolic link. The caller must free the
// return value.
export fn readlink(fs: *fs, path: str) (str | error) = {
diff --git a/hare/module/scan.ha b/hare/module/scan.ha
@@ -71,7 +71,11 @@ export fn scan(ctx: *context, path: str) (version | error) = {
...
};
scan_directory(ctx, &ver, &sha, path, iter)?;
- if (len(ver.inputs) == 0) {
+
+ let readme = path::join(path, "README");
+ defer free(readme);
+ if (len(ver.inputs) == 0 && !fs::exists(ctx.fs, readme)) {
+ // README is a special case for haredoc
return module_not_found;
};