1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Add Check to delete.lua (#236)

This commit is contained in:
JakobDev 2019-06-06 17:43:48 +02:00 committed by SquidDev
parent d8e1c73d26
commit 00c395f689
2 changed files with 9 additions and 1 deletions

View File

@ -9,7 +9,10 @@ for i = 1, args.n do
local files = fs.find(shell.resolve(args[i])) local files = fs.find(shell.resolve(args[i]))
if #files > 0 then if #files > 0 then
for n, file in ipairs(files) do for n, file in ipairs(files) do
fs.delete(file) local ok, err = pcall(fs.delete, file)
if not ok then
printError((err:gsub("^pcall: ", "")))
end
end end
else else
printError(args[i] .. ": No matching files") printError(args[i] .. ": No matching files")

View File

@ -39,6 +39,11 @@ describe("The rm program", function()
expect(capture(stub, "rm")) expect(capture(stub, "rm"))
:matches { ok = true, output = "Usage: rm <paths>\n", error = "" } :matches { ok = true, output = "Usage: rm <paths>\n", error = "" }
end) end)
it("errors when trying to delete a read-only file", function()
expect(capture(stub, "rm /rom/startup.lua"))
:matches { ok = true, output = "", error = "/rom/startup.lua: Access denied\n" }
end)
it("errors when a glob fails to match", function() it("errors when a glob fails to match", function()
expect(capture(stub, "rm", "never-existed")) expect(capture(stub, "rm", "never-existed"))