Skip to content

Adding kumo.fs.stat to get file/dir meta data#497

Merged
wez merged 5 commits intoKumoCorp:mainfrom
kayozaki:fs.stat
Apr 4, 2026
Merged

Adding kumo.fs.stat to get file/dir meta data#497
wez merged 5 commits intoKumoCorp:mainfrom
kayozaki:fs.stat

Conversation

@kayozaki
Copy link
Copy Markdown
Contributor

@kayozaki kayozaki commented Mar 25, 2026

  • Adding function to check the stat of a file or directory.

I personally wanted to get the last modified time of a file for the function i'm working on.
other attributes aren't necessarily required, but adding them as it may help others.

@kayozaki kayozaki marked this pull request as ready for review March 25, 2026 02:52
@kayozaki kayozaki changed the title Fs.stat Adding kumo.fs.stat to get file/dir meta data Mar 25, 2026
Comment thread crates/mod-filesystem/src/lib.rs Outdated
Comment thread crates/mod-filesystem/src/lib.rs Outdated
Comment thread crates/mod-filesystem/src/lib.rs Outdated
Comment thread crates/mod-filesystem/src/lib.rs Outdated
Copy link
Copy Markdown
Collaborator

@wez wez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! A couple of small changes and I think we're there!

Comment thread crates/mod-filesystem/src/lib.rs Outdated
Comment on lines +46 to +47
let atime_secs = this.0.atime();
system_time_to_lua_time(lua, Some(atime_secs))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of things for these time accessors:

  1. We have the nanosecond component available and we can feed that into chrono to get sub-second precision
  2. We don't need an Option around either seconds or nanoseconds
  3. There's an unwrap that we should avoid in case someone manages to put complete nonsense into time fields (eg: might happen if the fs is corrupt, but might also be possible if someone gets creative)

Something like this:

Suggested change
let atime_secs = this.0.atime();
system_time_to_lua_time(lua, Some(atime_secs))
let secs = this.0.atime();
let nsec = this.0.atime_nsec();
let dt = DateTime::<Utc>::from_timestamp(secs, nsec)
.map_err(mlua::Error::external)?;
Ok(Time::from(dt))

which you can also turn into a little macro for the 3 different timestamps or amend the system_time_to_lua_time helper function accordingly.


```lua
kumo.fs.metadata_for_path(path)
kumo.fs.symlink_metadata_for_path(path)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd appreciate having a separate doc page for symlink_metadata_for_path to make the search experience (potentially!) better, but it needn't copy the full text from here; it can have a stub paragraph below its synopsis and other metadata that says something like:

This function behaves exactly like [metadata_for_path](metadata_for_path.md),
except that it does not follow symbolic links and instead returns information
about the symbolic link itself.

@wez wez merged commit dc1cf4a into KumoCorp:main Apr 4, 2026
38 checks passed
@wez
Copy link
Copy Markdown
Collaborator

wez commented Apr 4, 2026

Thank you!

wez added a commit that referenced this pull request Apr 4, 2026
@kayozaki kayozaki deleted the fs.stat branch April 6, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants