santoku-fs
View on LuaRocksfilesystem library: whole-file and streamed I/O, path string helpers, traversal iterators, and a POSIX C extension, all raising structured errors
santoku-fs is the framework's filesystem library. It gives whole-file and streamed I/O, directory traversal iterators, and santoku.fs.posix, a thin POSIX C extension. Failures raise structured errors through santoku.error, so call sites use pcall instead of a nil check. santoku-fs sits under every native part of the stack, from toku build scripts to CLI tools.
Details
- The santoku.fs table merges the santoku.fs.posix primitives, stock io, and the pure-string path helpers of santoku.path.
- The path helpers below are santoku.path's. santoku.path also loads without santoku-fs, in a browser page too, and the santoku tab runs them live: https://santoku.dev/santoku
- An error carries the OS message plus errno. The module exports errno constants like fs.ENOENT and fs.EEXIST for matching.
- santoku.fs also carries every stock io field it doesn't define itself. So fs.lines, fs.type and fs.popen are io.lines, io.type and io.popen.
- fs.open, fs.read and fs.write are the raising wrappers below.
- santoku.fs needs a native or node host. A browser page has no filesystem, since the web profile's libc answers every open with ENOENT and has no directory calls.
- So santoku.fs.posix doesn't link into a page, and this site doesn't ship the library. The examples are shown for reading.
- hardlink, symlink, readlink and copytree are compiled out of any wasm build.
Path joins and names
join, dirname and basename work on path strings and never touch the disk. join inserts a separator only where one is needed.
local fs = require("santoku.fs")
print("join:", fs.join("a/", "b"))
print("join:", fs.join("srv", "web", "assets"))
print("join:", fs.join("srv", "/web"))
print("dirname:", fs.dirname("/opt/bin/sort"))
print("dirname:", fs.dirname("stdio.h"))
print("dirname:", fs.dirname("../../test"))
print("basename:", fs.basename("/opt/bin/sort"))
print("basename:", fs.basename("stdio.h"))
print("basename:", fs.basename("/home/user/"))
return fs.join("a", "b", "c")
Details
- A trailing slash on the left or a leading slash on the right suppresses the inserted separator.
- dirname of a bare name is the current directory.
- basename of a path that ends in a slash is nil.
Extensions
extension takes the last dot segment, and extensions takes everything from the first dot. The strip variants remove them. A name with no dot gives nil.
local fs = require("santoku.fs")
local arr = require("santoku.array")
print("extension:", fs.extension("release.tar.gz"))
print("extensions:", fs.extensions("release.tar.gz"))
print("stripextension:", fs.stripextension("release.tar.gz"))
print("stripextensions:", fs.stripextensions("release.tar.gz"))
print("no dot:", fs.extension("Makefile"))
local exts = {}
for e in fs.splitexts("/this/test.tar.gz", true) do
exts[#exts + 1] = e
end
print("splitexts:", arr.concat(exts, " "))
return fs.stripextensions("release.tar.gz")
Details
- splitexts iterates the extension parts, bare or with keep_dots.
Path components
splitparts iterates path components and collapses repeated slashes. stripparts drops n leading components.
local fs = require("santoku.fs")
local arr = require("santoku.array")
local plain = {}
for p in fs.splitparts("/deploy//web/assets/") do
plain[#plain + 1] = p
end
print("parts:", arr.concat(plain, " "))
local right = {}
for p in fs.splitparts("/deploy//web/assets/", "right") do
right[#right + 1] = p
end
print("right:", arr.concat(right, " "))
print("strip 2:", fs.stripparts("/home/user/a/b/c.txt", 2))
print("strip 4:", fs.stripparts("/home/user/a/b/c.txt", 4))
print("strip 0:", fs.stripparts("/home/user/a/b/c.txt", 0))
print("strip 5:", fs.stripparts("/home/user/a/b/c.txt", 5))
return fs.stripparts("/home/user/a/b/c.txt", 2)
Details
- A splitparts delim of right or left keeps the separators attached to one side.
- stripparts returns the path unchanged for 0, and nil when n consumes everything.
Whole-file round trips
writefile truncates by default and appends with the a flag, and readfile reads the whole file. mv renames, and touch creates an empty file.
local fs = require("santoku.fs")
fs.writefile("greeting.txt", "hello")
fs.writefile("greeting.txt", " world", "a")
print("contents:", fs.readfile("greeting.txt"))
fs.mv("greeting.txt", "renamed.txt")
fs.touch("empty.txt")
local found, kind = fs.exists("renamed.txt")
print("exists:", found, kind)
print("empty:", fs.readfile("empty.txt") == "")
fs.rm("renamed.txt")
fs.rm("empty.txt")
return fs.exists("greeting.txt")
Details
- exists returns two values: found, and the entry kind when found.
Path probes
exists, isdir and isfile stat the path and answer with plain booleans. They swallow only ENOENT: a missing path gives false, and any other failure still raises.
local fs = require("santoku.fs")
fs.mkdirp("probe/dir")
fs.writefile("probe/f.txt", "x")
print("isdir dir:", fs.isdir("probe/dir"))
print("isdir file:", fs.isdir("probe/f.txt"))
print("isfile file:", fs.isfile("probe/f.txt"))
print("isfile missing:", fs.isfile("probe/ghost"))
print("mode:", fs.mode("probe"))
local found, kind = fs.exists("probe/f.txt")
print("exists:", found, kind)
fs.rmdirs("probe")
return kind
Details
- mode gives the raw entry kind string that exists returns as its second value.
Structured errors
Failures raise through santoku.error with the OS message and errno. santoku.error's pcall spreads them back as values to match against the exported constants.
local fs = require("santoku.fs")
local err = require("santoku.error")
local ok, msg, code = err.pcall(fs.mode, "ghost")
print("ok:", ok)
print("message:", msg)
print("is ENOENT:", code == fs.ENOENT)
local ok2 = err.pcall(fs.rm, "ghost")
print("rm missing raises:", not ok2)
fs.rm("ghost", true)
print("rm allow_noexist:", "no raise")
return code == fs.ENOENT
Details
- rm raises on a missing path unless allow_noexist is passed.
Scoped handles
with opens a handle, runs your function with it, and always closes it. It then re-raises anything the function threw.
local fs = require("santoku.fs")
local err = require("santoku.error")
fs.writefile("data.txt", "line 1\nline 2\n")
local first = fs.with("data.txt", "r", function (fh)
return fs.read(fh, "*l")
end)
print("first line:", first)
local ok, msg = err.pcall(fs.with, "data.txt", "r", function ()
return err.error("boom")
end)
print("re-raised:", not ok, msg)
fs.rm("data.txt")
return first
Details
- Pass an already-open handle instead of a path, and with leaves closing it to you.
Handle primitives
open, read, write, seek, flush, setvbuf and close wrap the io methods with raising semantics. open returns the handle plus a was_open flag.
local fs = require("santoku.fs")
local fh = fs.open("notes.txt", "w")
fs.setvbuf(fh, "full")
fs.write(fh, "alpha\nbeta\n")
fs.flush(fh)
fs.close(fh)
fh = fs.open("notes.txt", "r")
print("first:", fs.read(fh, "*l"))
print("seek:", fs.seek(fh, "set", 6))
print("second:", fs.read(fh, "*l"))
local same, was_open = fs.open(fh)
print("passthrough:", same == fh, was_open)
fs.close(fh)
fs.rm("notes.txt")
return was_open
Details
- setvbuf(fh, "no" or "full" or "line"[, size]) sets a handle's buffering.
- Given an existing handle, open passes it through with true. That's how with and chunks accept either a path or a handle.
Anonymous scratch handles since santoku-fs 2.4.2
tmpfile() is io.tmpfile with raising semantics. It returns an ordinary file handle opened for update, and the file disappears when the handle closes or the program exits.
local fs = require("santoku.fs")
local fh = fs.tmpfile()
print("type:", fs.type(fh))
fs.write(fh, "hello")
print("at:", fs.seek(fh, "cur"))
fs.seek(fh, "set")
print("read:", fs.read(fh, "*a"))
fs.close(fh)
return fs.type(fh)
Details
- Every handle primitive accepts the handle.
- An unclosed handle is safe to collect.
- Use tmpname instead when a path has to reach another process.
- The specs skip tmpfile under WebAssembly.
Standard handles
fs.stdout, fs.stderr and fs.stdin are the process's standard handles, io.stdout, io.stderr and io.stdin. Pass one to fs.write, fs.read or fs.flush like any other handle.
local fs = require("santoku.fs")
local sys = require("santoku.system")
local err = require("santoku.error")
local path = arg[1]
local ok, text = err.pcall(fs.readfile, path)
if not ok then
fs.write(fs.stderr, "my-tool: can't read ", tostring(path), "\n")
sys.exit(1)
end
fs.write(fs.stdout, #text, " bytes\n")
Details
- fs.write always takes a handle first, so it has no default stream.
- A bin script reports a failure on fs.stderr and exits nonzero with sys.exit.
Directory trees
mkdirp creates every missing component and is idempotent. rmdirs removes a directory and everything under it.
local fs = require("santoku.fs")
local err = require("santoku.error")
fs.mkdirp("deep/x/y")
print("created:", fs.isdir("deep/x/y"))
fs.mkdirp("deep/x/y")
print("mkdirp again:", "no raise")
local ok, _, code = err.pcall(fs.mkdir, "deep")
print("mkdir again:", ok, code == fs.EEXIST)
for d in fs.dirs("deep", true, true) do
print("leaves-first:", d)
end
fs.rmdirs("deep")
return fs.exists("deep")
Details
- The raw mkdir raises EEXIST on a second call.
- dirs with leaves true yields children before their parents.
- The Recursive remove and copy card covers what rmdirs removes and when it raises.
File and directory iterators
files iterates regular files and dirs iterates directories, each with a recurse flag. Without the flag, files stays in the top level, and dirs lists immediate subdirectories without descending.
local fs = require("santoku.fs")
local arr = require("santoku.array")
fs.mkdirp("proj/src/util")
fs.writefile("proj/readme.md", "# proj")
fs.writefile("proj/src/main.lua", "return true")
fs.writefile("proj/src/util/str.lua", "return true")
local all = {}
for fp in fs.files("proj", true) do
all[#all + 1] = fp
end
arr.sort(all)
print("recursive:", arr.concat(all, " "))
local top = {}
for fp in fs.files("proj") do
top[#top + 1] = fp
end
print("top only:", arr.concat(top, " "))
local kept = {}
for fp in fs.files("proj", true, function (name) return fs.basename(name) == "util" end) do
kept[#kept + 1] = fp
end
arr.sort(kept)
print("pruned util:", arr.concat(kept, " "))
local ds = {}
for d in fs.dirs("proj", true) do
ds[#ds + 1] = d
end
arr.sort(ds)
print("dirs:", arr.concat(ds, " "))
fs.rmdirs("proj")
return #all
Details
- files takes a third argument, prune(name, kind), called for each directory. A true return skips that directory and everything under it.
- Directory order comes from readdir, so collect and sort when order matters.
Walk with prune
walk yields every entry as name, kind. The prune callback runs for each directory, and its return decides whether walk descends.
local fs = require("santoku.fs")
local arr = require("santoku.array")
fs.mkdirp("site/src")
fs.mkdirp("site/build")
fs.writefile("site/src/main.lua", "return true")
fs.writefile("site/build/cache.bin", "x")
fs.writefile("site/doc.md", "# doc")
local seen = {}
for name, kind in fs.walk("site", function (dir)
if fs.basename(dir) == "build" then
return true
end
end) do
seen[#seen + 1] = name .. " (" .. kind .. ")"
end
arr.sort(seen)
print("pruned:", arr.concat(seen, " "))
local kept = {}
for name, kind in fs.walk("site", function ()
return "keep"
end) do
kept[#kept + 1] = name .. " (" .. kind .. ")"
end
arr.sort(kept)
print("keep:", arr.concat(kept, " "))
fs.rmdirs("site")
return #seen
Details
- true skips the subtree entirely.
- The string keep yields the directory itself without descending. Non-recursive dirs works this way.
- false descends normally.
The raw directory stream
dir wraps the raw diropen, dirent and dirclose primitives into an iterator over entry name and kind. It includes the dot entries, which callers filter themselves.
local fs = require("santoku.fs")
local arr = require("santoku.array")
fs.mkdirp("box")
fs.writefile("box/a.txt", "a")
fs.writefile("box/b.txt", "b")
local ents = {}
for name, kind in fs.dir("box") do
if name ~= "." and name ~= ".." then
ents[#ents + 1] = name .. " (" .. kind .. ")"
end
end
arr.sort(ents)
print(arr.concat(ents, ", "))
fs.rmdirs("box")
return #ents
Details
- The handle closes itself at end of stream and carries a __gc closer for early exits.
Fixed-size chunks
With no delimiters, chunks streams a file in blocks of at most the given size, each yielded as a fresh string. The buffer size defaults to BUFSIZ when omitted.
local fs = require("santoku.fs")
fs.writefile("blob.txt", "line 1\nline 2\nline 3\nline 4\n")
local blocks = {}
for chunk in fs.chunks("blob.txt", nil, 8) do
blocks[#blocks + 1] = chunk
end
print("count:", #blocks)
print("first:", (blocks[1]:gsub("\n", "\\n")))
print("last:", (blocks[#blocks]:gsub("\n", "\\n")))
fs.rm("blob.txt")
return #blocks
Details
- A 28-byte file read 8 bytes at a time gives three full blocks and a 4-byte tail.
Delimited chunks
With delimiter bytes, chunks yields the buffer plus the start and end positions of each segment, so it slices without copying.
local fs = require("santoku.fs")
local err = require("santoku.error")
local arr = require("santoku.array")
fs.writefile("log.txt", "alpha\nbeta\ngamma\n")
local lines = {}
for chunk, s, e in fs.chunks("log.txt", "\n", 8, true) do
lines[#lines + 1] = chunk:sub(s, e)
end
print("lines:", arr.concat(lines, ", "))
local ok, msg = err.pcall(function ()
for chunk in fs.chunks("log.txt", "\n", 3) do
local _ = chunk
end
end)
print("too small:", not ok, msg)
fs.rm("log.txt")
return #lines
Details
- omit true excludes the delimiter run from the end position.
- chunks re-reads a record that spans a buffer boundary.
- A record larger than the buffer raises chunk doesn't fit, with the byte offsets.
pushd
pushd changes into a directory and calls your function with any extra arguments. It restores the previous cwd on every exit path, and on error it restores first, then re-raises.
local fs = require("santoku.fs")
local err = require("santoku.error")
fs.mkdirp("scratch")
local before = fs.cwd()
local inside = fs.pushd("scratch", function (tag)
fs.writefile("note.txt", tag)
return fs.cwd()
end, "written inside")
print("changed:", inside ~= before)
print("restored:", fs.cwd() == before)
print("note:", fs.readfile("scratch/note.txt"))
local ok, msg = err.pcall(fs.pushd, "scratch", function ()
return err.error("inner failure")
end)
print("re-raised:", not ok, msg)
print("still restored:", fs.cwd() == before)
print("not empty:", err.pcall(fs.rmdir, "scratch"))
fs.cd("scratch")
print("cd:", fs.basename(fs.cwd()))
fs.cd(before)
fs.rm("scratch/note.txt")
fs.rmdir("scratch")
return fs.basename(inside)
Details
- The make engine runs each dependency build inside its own checkout this way.
- cwd() reads the current directory.
- cd(dir) changes the current directory with no restore.
- rmdir(dir) removes one empty directory. Otherwise it raises with the errno message and code, such as "Directory not empty" and 39 on Linux.
loadfile and runfile
loadfile compiles a Lua file to a function under an optional environment, and runfile loads and calls it.
local fs = require("santoku.fs")
fs.writefile("script.lua", "return x + y")
print("loadfile:", fs.loadfile("script.lua", { x = 1, y = 2 })())
local result = fs.runfile("script.lua", { x = 10, y = 20 })
print("runfile:", result)
fs.writefile("script.lua", "return print ~= nil")
print("sees _G:", fs.runfile("script.lua"))
print("isolated:", fs.runfile("script.lua", {}, true))
fs.rm("script.lua")
return result
Details
- runfile's environment falls through to _G by default, so scripts can still reach globals.
- The nog flag cuts that link for full isolation.
Absolute and relative paths
absolute resolves a path against the real filesystem with realpath. It walks back to the deepest existing prefix, so a not-yet-created leaf still gets an absolute answer.
local fs = require("santoku.fs")
fs.mkdirp("abs/demo")
local a = fs.absolute("abs/demo")
print("relative:", fs.relative(a), fs.relative("/etc/hosts", "/srv"))
print("anchored:", a == fs.join(fs.cwd(), "abs/demo"))
local leaf = fs.absolute("abs/demo/new.txt")
print("missing leaf:", leaf == fs.join(fs.cwd(), "abs/demo/new.txt"))
print("empty:", fs.absolute("") == nil)
fs.rmdirs("abs")
return a ~= nil
Details
- The empty string gives nil.
- relative(fp, base) goes the other way. It strips base from fp the way santoku.path's relative does.
- base defaults to the current directory.
- relative returns fp unchanged when fp lies outside base.
The copy idiom
The make engine copies a file this way everywhere: mkdirp the destination's dirname, then writefile a readfile. Drive it from a files iteration to mirror a whole tree.
local fs = require("santoku.fs")
local arr = require("santoku.array")
local function copy (src, dest)
fs.mkdirp(fs.dirname(dest))
fs.writefile(dest, fs.readfile(src))
end
fs.mkdirp("src/icons")
fs.writefile("src/app.lua", "return 1")
fs.writefile("src/icons/logo.svg", "<svg/>")
for fp in fs.files("src", true) do
copy(fp, fs.join("dist", fp))
end
local out = {}
for fp in fs.files("dist", true) do
out[#out + 1] = fp
end
arr.sort(out)
print("mirrored:", arr.concat(out, " "))
local body = fs.readfile("dist/src/app.lua")
fs.rmdirs("src")
fs.rmdirs("dist")
return body
Details
- This idiom copies regular files only. copytree also copies symlinks, modes and owners.
Metadata and permissions
stat follows symlinks and returns one table of file metadata. fs.mtime and fs.stamp tell whether a file changed. chmod, chown and umask set permissions and ownership.
local fs = require("santoku.fs")
local str = require("santoku.string")
fs.writefile("perm.txt", "abc")
fs.chmod("perm.txt", "600")
local st = fs.stat("perm.txt")
print("type:", st.type, "size:", st.size)
print("perms:", str.format("%o", st.perms))
fs.chmod("perm.txt", 420)
print("perms:", str.format("%o", fs.stat("perm.txt").perms))
local before = fs.stamp("perm.txt")
print("mtime:", fs.mtime("perm.txt"), "ns:", st.mtime_ns)
fs.writefile("perm.txt", "abcd")
print("stamp changed:", before ~= fs.stamp("perm.txt"))
local tree = fs.treestamp({ "perm.txt" })
fs.writefile("perm.txt", "abcde")
print("treestamp changed:", tree ~= fs.treestamp({ "perm.txt" }))
fs.chown("perm.txt", -1, -1)
local old = fs.umask("022")
print("umask was:", str.format("%o", old), "now:", str.format("%o", fs.umask()))
fs.umask(old)
fs.rm("perm.txt")
return st.type
Details
| stat field | holds |
|---|---|
| type | the same string mode gives |
| perms | the permission bits as an integer |
| size, mtime, atime, ctime | size and times in seconds |
| mtime_ns, atime_ns, ctime_ns | the nanoseconds within those seconds |
| uid, gid, nlink, ino, dev | ownership, link count and identity |
- fs.mtime(path) returns the mtime as one number with its fraction, for comparing build inputs.
- fs.stamp(path) returns dev:ino:size:mtime:ctime as a string, with each time in seconds and nanoseconds.
- Compare two stamps with == to tell whether a file changed.
- A rewrite that changes the size, or replaces the file by rename, changes the stamp even when the mtime doesn't move.
- A same-size rewrite in place within one timestamp tick keeps the stamp.
- stat, fs.mtime and fs.stamp raise ENOENT for a missing path.
- fs.mtime, fs.stamp and the _ns fields ship from santoku-fs 2.5.0.
- fs.treestamp(paths) takes a list of paths and returns one string. The string changes when a file under them is added, removed or gets a different fs.stamp.
- fs.treestamp walks the files that fs.files(path, true) yields for a directory, stamps a path that names anything else, and skips a missing path.
- The string names no file. When it changes, list the files and compare their stamps to find which changed.
- fs.treestamp ships from santoku-fs 2.6.0.
- chmod and umask take the mode as an integer or as an octal string, since Lua has no octal literal.
- chown takes a uid and gid, and leaves either unchanged when it's -1 or nil.
- umask returns the previous mask, and with no argument only reads it.
- A server whose master process creates a file that its workers write calls chmod or chown right after creating it. A query log under nginx is one case.
hardlink and symlink
hardlink and symlink are compiled out of wasm builds, where __wasm__ is defined. Feature-detect them with a nil check, as the library's own tests do.
local fs = require("santoku.fs")
if fs.hardlink then
fs.writefile("shared.txt", "hello")
fs.hardlink("shared.txt", "alias.txt")
print("alias:", fs.readfile("alias.txt"))
fs.writefile("shared.txt", "changed")
print("alias sees:", fs.readfile("alias.txt"))
end
if fs.symlink then
fs.symlink("shared.txt", "pointer.txt")
print("mode:", fs.mode("pointer.txt"))
fs.symlink("missing.txt", "dangling.txt")
print("dangling exists:", fs.exists("dangling.txt"))
end
Details
- A hardlink shares content with its source.
- mode follows a symlink to the target's kind.
- exists on a dangling symlink is false, because stat fails with ENOENT.
readlink and access since santoku-fs 2.7.0
readlink returns the target a symlink names, without resolving it. access asks the kernel whether this process may read, write or execute a path.
local fs = require("santoku.fs")
fs.writefile("conf.txt", "x")
fs.chmod("conf.txt", "600")
print("exists:", fs.access("conf.txt", ""))
print("rw:", fs.access("conf.txt", "rw"))
print("x:", fs.access("conf.txt", "x"))
print("missing:", fs.access("nope.txt", "r"))
if fs.readlink then
fs.symlink("conf.txt", "conf.link")
print("target:", fs.readlink("conf.link"))
fs.rm("conf.link")
end
fs.rm("conf.txt")
Details
- readlink raises EINVAL on a path that isn't a symlink and ENOENT on a missing path.
- readlink returns a dangling link's target too.
- readlink is compiled out of wasm builds, beside symlink.
- access(path, mode) takes mode as a string of the letters r, w and x, and "" asks only whether the path exists.
- access returns true or false from access(2), checked against the real uid and gid.
- access returns false when the path is missing, a component isn't a directory, or the permission is denied.
- access raises on a mode letter other than r, w or x, and on an I/O error.
Recursive remove and copy since santoku-fs 2.7.0
rmdirs removes a directory and everything under it. copytree copies a file, a symlink or a whole directory tree to a path that doesn't exist yet.
local fs = require("santoku.fs")
local err = require("santoku.error")
fs.mkdirp("rootfs/bin")
fs.writefile("rootfs/bin/tool", "#!/bin/sh\n")
fs.chmod("rootfs/bin/tool", "755")
if fs.copytree then
fs.symlink("bin/tool", "rootfs/tool")
fs.copytree("rootfs", "rootfs.copy")
print("link:", fs.readlink("rootfs.copy/tool"))
print("perms:", fs.stat("rootfs.copy/bin/tool").perms == fs.stat("rootfs/bin/tool").perms)
local ok, _, code, fp = err.pcall(fs.copytree, "rootfs", "rootfs.copy")
print("again:", ok, code == fs.EEXIST, fp)
fs.rmdirs("rootfs.copy")
end
fs.rmdirs("rootfs")
print("gone:", fs.exists("rootfs"))
Details
- rmdirs unlinks a symlink inside the tree and never follows it, so the link's target stays.
- rmdirs raises ENOTDIR when the path itself is a file or a symlink, and ENOENT when it's missing.
- rmdirs stops at the first entry it can't remove and raises with that entry's path as the third value. Entries removed before it stay removed.
- Before santoku-fs 2.7.0, rmdirs removed empty directories only.
- copytree copies regular files, directories and symlinks. A symlink is copied as a link with the same target, never followed.
- copytree keeps each entry's permission bits, setuid, setgid and sticky included.
- copytree keeps the owner and group when the process may set them, as root can. Otherwise the copy belongs to the process.
- copytree raises EEXIST when the destination or any path under it exists, and never overwrites.
- copytree raises on a fifo, socket or device, and when the destination lies inside the source. The error's third value is the path.
- copytree doesn't keep timestamps or hardlinks. Two hardlinked files become two files.
- A copytree that raises leaves what it copied so far in place.
- copytree is compiled out of wasm builds.
Host tooling idioms
These patterns come from the CLI tools and build scripts, and only make sense on a real machine.
local fs = require("santoku.fs")
local err = require("santoku.error")
local ok, raw = err.pcall(fs.readfile, "ll.conf.lua")
if not ok then
raw = "return {}"
end
local canonical = fs.absolute("notes/sync.md")
if fs.exists("notes/sync.md") then
print("syncing:", canonical)
end
local tmp = fs.tmpname() .. ".c"
fs.writefile(tmp, "int main () { return 0; }")
print("scratch:", tmp)
fs.rm(tmp)
return canonical
Details
- pcall a readfile to treat a missing config as defaults.
- absolute canonicalizes a user path before the tool records it.
- exists is a cheap guard.
- tmpname names compiler scratch files.