-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrm.lua
More file actions
23 lines (23 loc) · 862 Bytes
/
rm.lua
File metadata and controls
23 lines (23 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local filesystem = require "system.filesystem"
local util = require "system.util"
local args = assert(util.argparse({f = false, i = false, R = "@r", r = false, ["no-preserve-root"] = false}, ...))
local retval = true
for _, v in ipairs(args) do
local stat = filesystem.stat(v)
if not args["no-preserve-root"] and filesystem.combine(v) == "/" then
io.stderr:write("rm: refusing to remove root directory")
elseif not stat then
if not args.f then io.stderr:write("rm: " .. v .. ": No such file or directory\n") end
retval = false
elseif stat.type == "directory" then
if args.r then
filesystem.remove(v)
else
io.stderr:write("rm: -r not specified, skipping directory " .. v .. "\n")
retval = false
end
else
filesystem.remove(v)
end
end
return retval