Skip to content

Add filesystem metadata helpers to hslua-module-system#161

Open
tionis wants to merge 1 commit into
hslua:mainfrom
tionis:main
Open

Add filesystem metadata helpers to hslua-module-system#161
tionis wants to merge 1 commit into
hslua:mainfrom
tionis:main

Conversation

@tionis
Copy link
Copy Markdown

@tionis tionis commented May 8, 2026

This adds two filesystem metadata helpers to hslua-module-system:

  • system.stat(path): returns metadata for a single file or directory.
  • system.ls_with_metadata([directory]): lists directory entries together with metadata.

The metadata table includes:

  • name
  • path
  • type
  • size
  • modification_time
  • access_time
  • permissions
  • is_symlink

This addresses #145 and provides the HsLua-side functionality needed for jgm/pandoc#9422.

Notes

ls remains unchanged, so existing callers keep receiving a plain list of filenames.

Testing

  • cabal test hslua-module-system
  • git diff --check
  • lua -e 'assert(loadfile("hslua-module-system/test/test-system.lua"))'

Copilot AI review requested due to automatic review settings May 8, 2026 22:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends hslua-module-system with filesystem metadata capabilities, adding Lua-facing helpers to stat a single path and to list a directory while returning per-entry metadata (motivated by #145 / pandoc scripting needs).

Changes:

  • Added system.stat(path) to return metadata for a file or directory.
  • Added system.ls_with_metadata([dir]) to list directory entries along with metadata.
  • Updated docs/tests/changelog and bumped hslua-module-system to 1.3.1 (plus new filepath dependency).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
hslua-module-system/src/HsLua/Module/System.hs Implements stat/ls_with_metadata and metadata marshaling helpers.
hslua-module-system/test/test-system.lua Adds test coverage for the new functions and returned metadata shape.
hslua-module-system/README.md Documents the new functions in the module README.
hslua-module-system/hslua-module-system.cabal Bumps version to 1.3.1 and adds filepath dependency.
hslua-module-system/CHANGELOG.md Adds a 1.3.1 entry describing the new API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +671 to +686
isSymlink <- if pathExists
then Directory.pathIsSymbolicLink path
else pure False
isFile <- Directory.doesFileExist path
isDirectory <- Directory.doesDirectoryExist path
let fileType
| isSymlink = "symlink"
| isDirectory = "directory"
| isFile = "file"
| otherwise = "other"
size <- if isFile
then Just <$> Directory.getFileSize path
else pure Nothing
modificationTime <- Directory.getModificationTime path
accessTime <- Directory.getAccessTime path
permissions <- Directory.getPermissions path
stat :: LuaError e => DocumentedFunction e
stat = defun "stat"
### (\filepath -> ioToLua $
getFileMetadata (FilePath.takeFileName filepath) filepath)
Comment on lines +427 to +428
, "The returned table contains the path, type, size, permissions,"
, "access time, and modification time."
Comment on lines +232 to +243
Obtain metadata for a file or directory. The returned table contains
the path, type, size, permissions, access time, and modification time.

Parameters:

`filepath`
: file or directory path (string)

Returns:

- file metadata (table)

Comment on lines +5 to +11
## hslua-module-system-1.3.1

Released pending.

- Added new functions `stat` and `ls_with_metadata`, which return
file metadata such as type, size, permissions, access time, and
modification time.
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