Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/scripts/reference.luau
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ local function processDirectory(
)
fs.createdirectory(documentationPath, { makeparents = true })

local entries = fs.listdir(modulePath)
local entries = fs.listdirectory(modulePath)

for _, entry in entries do
local entryPath = path.join(modulePath, entry.name)
Expand Down
16 changes: 0 additions & 16 deletions examples/async_read.luau

This file was deleted.

2 changes: 1 addition & 1 deletion examples/create_directory.luau
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else
print("Failed to create directory")
end

fs.rmdir(directory)
fs.removedirectory(directory)

if not fs.exists(directory) then
print("Directory successfully removed")
Expand Down
2 changes: 1 addition & 1 deletion lute/cli/commands/test/finder.luau
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end
local function findtestfilesrec(directory: path.path): { path.path }
local results = {}

for _, entry in fs.listdir(directory) do
for _, entry in fs.listdirectory(directory) do
local fullPath = path.join(directory, entry.name)

if entry.type == "dir" then
Expand Down
43 changes: 18 additions & 25 deletions lute/std/libs/fs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ local sys = require("@std/system")
local fslib = {}

export type handlemode = fs.HandleMode
export type filehandle = fs.FileHandle
export type filetype = fs.FileType
export type filemetadata = fs.FileMetadata
export type file = fs.FileHandle
export type type = fs.FileType
export type metadata = fs.FileMetadata
export type directoryentry = fs.DirectoryEntry
export type watchhandle = fs.WatchHandle
export type watchevent = fs.WatchEvent
export type pathlike = pathlib.pathlike

type pathlike = pathlib.pathlike
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

an aside, but we should really name this type path if it's the one everyone is writing everywhere.


export type createdirectoryoptions = {
makeparents: boolean?,
Expand All @@ -30,39 +31,39 @@ export type walkoptions = {
recursive: boolean?,
}

function fslib.open(path: pathlike, mode: handlemode?): filehandle
function fslib.open(path: pathlike, mode: handlemode?): file
return fs.open(pathlib.format(path), mode)
end

function fslib.read(handle: filehandle): string
return fs.read(handle)
function fslib.read(file: file): string
return fs.read(file)
end

function fslib.write(handle: filehandle, contents: string): ()
return fs.write(handle, contents)
function fslib.write(file: file, contents: string): ()
return fs.write(file, contents)
end

function fslib.close(handle: filehandle): ()
return fs.close(handle)
function fslib.close(file: file): ()
return fs.close(file)
end

function fslib.remove(path: pathlike): ()
return fs.remove(pathlib.format(path))
end

function fslib.stat(path: pathlike): filemetadata
function fslib.metadata(path: pathlike): metadata
return fs.stat(pathlib.format(path))
end

function fslib.type(path: pathlike): filetype
function fslib.type(path: pathlike): type
return fs.type(pathlib.format(path))
end

function fslib.link(src: pathlike, dest: pathlike): ()
return fs.link(pathlib.format(src), pathlib.format(dest))
end

function fslib.symlink(src: pathlike, dest: pathlike): ()
function fslib.symboliclink(src: pathlike, dest: pathlike): ()
return fs.symlink(pathlib.format(src), pathlib.format(dest))
end

Expand All @@ -78,14 +79,10 @@ function fslib.copy(src: pathlike, dest: pathlike): ()
return fs.copy(pathlib.format(src), pathlib.format(dest))
end

function fslib.listdir(path: pathlike): { directoryentry }
function fslib.listdirectory(path: pathlike): { directoryentry }
return fs.listdir(pathlib.format(path))
end

function fslib.rmdir(path: pathlike): ()
return fs.rmdir(pathlib.format(path))
end

function fslib.readfiletostring(filepath: pathlike): string
return fs.readfiletostring(pathlib.format(filepath))
end
Expand All @@ -94,10 +91,6 @@ function fslib.writestringtofile(filepath: pathlike, contents: string): ()
return fs.writestringtofile(pathlib.format(filepath), contents)
end

function fslib.readasync(filepath: pathlike): string
return fs.readasync(pathlib.format(filepath))
end

function fslib.createdirectory(path: pathlike, options: createdirectoryoptions?): ()
if options and options.makeparents then
local parsed = pathlib.parse(path)
Expand Down Expand Up @@ -129,7 +122,7 @@ function fslib.removedirectory(path: pathlike, options: removedirectoryoptions?)
if options and options.recursive then
-- Recursively delete all contents first
if fslib.exists(path) and fslib.type(path) == "dir" then
local entries = fslib.listdir(path)
local entries = fslib.listdirectory(path)
for _, entry in entries do
local entryPath = pathlib.join(path, entry.name)
if entry.type == "dir" then
Expand Down Expand Up @@ -157,7 +150,7 @@ function fslib.walk(path: pathlike, options: walkoptions?): () -> path?
end

if fslib.type(current) == "dir" and options and options.recursive then
local entries = fslib.listdir(current)
local entries = fslib.listdirectory(current)
for _, entry in entries do
local fullPath = pathlib.join(current, entry.name)
table.insert(queue, fullPath)
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/loadbypath.test.luau
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test.suite("Lute CLI Run", function(suite)

suite:afterall(function()
if fs.exists(testDirStr) then
fs.rmdir(testDirStr)
fs.removedirectory(testDirStr)
end
end)
end)
Expand Down
24 changes: 7 additions & 17 deletions tests/std/fs.test.luau
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test.suite("FsSuite", function(suite)
fs.write(h, "abc")
fs.close(h)

local m = fs.stat(file)
local m = fs.metadata(file)
assert.eq(m.size, 3)

local hr = fs.open(file, "r")
Expand Down Expand Up @@ -55,25 +55,15 @@ test.suite("FsSuite", function(suite)
assert.eq(fs.exists(dir), true)
assert.eq(fs.type(dir), "dir")

local entries = fs.listdir(tmpdir)
local entries = fs.listdirectory(tmpdir)
local found = false
for _, e in entries do
if e.name == "subdir" then
found = true
end
end
assert.eq(found, true)
fs.rmdir(dir)
end)

suite:case("readasync_and_writestring", function(assert)
local file = path.join(tmpdir, "async.txt")
fs.writestringtofile(file, "async content")

local got = fs.readasync(file)
assert.eq(got, "async content")

fs.remove(file)
fs.removedirectory(dir)
end)

suite:case("link_and_symlink_and_copy", function(assert)
Expand All @@ -92,7 +82,7 @@ test.suite("FsSuite", function(suite)
fs.remove(dstcopy)

local dstsymlink = path.join(tmpdir, "dstsymlink")
fs.symlink(srcfile, dstsymlink)
fs.symboliclink(srcfile, dstsymlink)
assert.eq(fs.readfiletostring(dstsymlink), "linkcontent")
fs.remove(dstsymlink)

Expand Down Expand Up @@ -131,8 +121,8 @@ test.suite("FsSuite", function(suite)
fs.createdirectory(nestedDir, { makeparents = true })
assert.eq(fs.exists(nestedDir), true)

fs.rmdir(nestedDir)
fs.rmdir(path.join(tmpdir, "nested"))
fs.removedirectory(nestedDir)
fs.removedirectory(path.join(tmpdir, "nested"))
end)

suite:case("createdirectory_makeparents_false", function(assert)
Expand Down Expand Up @@ -223,7 +213,7 @@ test.suite("FsSuite", function(suite)

-- Cleanup
fs.remove(file)
fs.rmdir(dir)
fs.removedirectory(dir)
end)

suite:case("walk_directory_recursive", function(assert)
Expand Down
2 changes: 1 addition & 1 deletion tests/std/syntax/parser.test.luau
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ test.suite("Parser", function(suite)

suite:case("roundtrippableAst", function(assert)
local function visitDirectory(directory: string)
for _, entry in fs.listdir(directory) do
for _, entry in fs.listdirectory(directory) do
if entry.type ~= "file" then
continue
end
Expand Down