hare

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

commit fdd654705289f6e6f07709e23cc14310a46b260d
parent 79b5756e08b87a0d2e10ee74093e4040180688c0
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 14 Mar 2021 12:58:08 -0400

fs: add times to stat

Diffstat:
Mfs/types.ha | 8+++++++-
Mgen-stdlib | 2+-
Mos/+linux/dirfdfs.ha | 20+++++++++++++++++---
Mstdlib.mk | 4++--
4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/fs/types.ha b/fs/types.ha @@ -1,6 +1,7 @@ use io; use strings; use path; +use time; // An entry was requested which does not exist. export type noentry = void!; @@ -101,6 +102,9 @@ export type stat_mask = enum uint { GID = 1 << 1, SIZE = 1 << 2, INODE = 1 << 3, + ATIME = 1 << 4, + MTIME = 1 << 5, + CTIME = 1 << 6, }; // Information about a file or directory. The mask field defines what other @@ -112,7 +116,9 @@ export type filestat = struct { gid: uint, sz: size, inode: u64, - // TODO: atime et al + atime: time::time, + mtime: time::time, + ctime: time::time, }; // An entry in a directory. This may be borrowed from the filesystem's internal diff --git a/gen-stdlib b/gen-stdlib @@ -217,7 +217,7 @@ fs() { types.ha \ fs.ha \ util.ha - gen_ssa fs io strings path + gen_ssa fs io strings path time } getopt() { diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -5,8 +5,7 @@ use io; use path; use rt; use strings; - -use strconv; +use time; // Controls how symlinks are followed (or not) in a dirfd filesystem. Support // for this feature varies, you should gate usage of this enum behind a build @@ -216,12 +215,27 @@ fn fs_stat(fs: *fs::fs, path: str) (fs::filestat | fs::error) = { mask = fs::stat_mask::UID | fs::stat_mask::GID | fs::stat_mask::SIZE - | fs::stat_mask::INODE, + | fs::stat_mask::INODE + | fs::stat_mask::ATIME + | fs::stat_mask::MTIME + | fs::stat_mask::CTIME, mode = st.mode: fs::mode, uid = st.uid, uid = st.gid, sz = st.sz, inode = st.ino, + atime = time::time { + sec = st.atime.tv_sec, + nsec = st.atime.tv_nsec, + }, + mtime = time::time { + sec = st.mtime.tv_sec, + nsec = st.mtime.tv_nsec, + }, + ctime = time::time { + sec = st.ctime.tv_sec, + nsec = st.ctime.tv_nsec, + }, }; }; diff --git a/stdlib.mk b/stdlib.mk @@ -307,7 +307,7 @@ stdlib_fs_srcs= \ $(STDLIB)/fs/fs.ha \ $(STDLIB)/fs/util.ha -$(HARECACHE)/fs/fs.ssa: $(stdlib_fs_srcs) $(stdlib_rt) $(stdlib_io) $(stdlib_strings) $(stdlib_path) +$(HARECACHE)/fs/fs.ssa: $(stdlib_fs_srcs) $(stdlib_rt) $(stdlib_io) $(stdlib_strings) $(stdlib_path) $(stdlib_time) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/fs @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nfs \ @@ -873,7 +873,7 @@ testlib_fs_srcs= \ $(STDLIB)/fs/fs.ha \ $(STDLIB)/fs/util.ha -$(TESTCACHE)/fs/fs.ssa: $(testlib_fs_srcs) $(testlib_rt) $(testlib_io) $(testlib_strings) $(testlib_path) +$(TESTCACHE)/fs/fs.ssa: $(testlib_fs_srcs) $(testlib_rt) $(testlib_io) $(testlib_strings) $(testlib_path) $(testlib_time) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/fs @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nfs \