Revert "fix: avoid following symlinks in `common.rm`"
This reverts commit e3e8badf99
.
This commit is contained in:
parent
e3e8badf99
commit
f5df5d6626
|
@ -672,10 +672,10 @@ end
|
||||||
function common.rm(path, recursively)
|
function common.rm(path, recursively)
|
||||||
local stat = system.get_file_info(path)
|
local stat = system.get_file_info(path)
|
||||||
if not stat or (stat.type ~= "file" and stat.type ~= "dir") then
|
if not stat or (stat.type ~= "file" and stat.type ~= "dir") then
|
||||||
return false, "invalid path", path
|
return false, "invalid path given", path
|
||||||
end
|
end
|
||||||
|
|
||||||
if stat.type == "file" or stat.symlink then
|
if stat.type == "file" then
|
||||||
local removed, error = os.remove(path)
|
local removed, error = os.remove(path)
|
||||||
if not removed then
|
if not removed then
|
||||||
return false, error, path
|
return false, error, path
|
||||||
|
@ -687,9 +687,23 @@ function common.rm(path, recursively)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, item in pairs(contents) do
|
for _, item in pairs(contents) do
|
||||||
local removed, error, error_path = common.rm(path .. PATHSEP .. item, recursively)
|
local item_path = path .. PATHSEP .. item
|
||||||
if not removed then
|
local item_stat = system.get_file_info(item_path)
|
||||||
return false, error, error_path
|
|
||||||
|
if not item_stat then
|
||||||
|
return false, "invalid file encountered", item_path
|
||||||
|
end
|
||||||
|
|
||||||
|
if item_stat.type == "dir" then
|
||||||
|
local deleted, error, ipath = common.rm(item_path, recursively)
|
||||||
|
if not deleted then
|
||||||
|
return false, error, ipath
|
||||||
|
end
|
||||||
|
elseif item_stat.type == "file" then
|
||||||
|
local removed, error = os.remove(item_path)
|
||||||
|
if not removed then
|
||||||
|
return false, error, item_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue