Add filesystem metadata helpers to hslua-module-system#161
Open
tionis wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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-systemto 1.3.1 (plus newfilepathdependency).
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
namepathtypesizemodification_timeaccess_timepermissionsis_symlinkThis addresses #145 and provides the HsLua-side functionality needed for jgm/pandoc#9422.
Notes
lsremains unchanged, so existing callers keep receiving a plain list of filenames.Testing
cabal test hslua-module-systemgit diff --checklua -e 'assert(loadfile("hslua-module-system/test/test-system.lua"))'