Skip to content
Snippets Groups Projects
Commit 564a053c authored by Konstantin Belyavskiy's avatar Konstantin Belyavskiy Committed by Konstantin Osipov
Browse files

lua: fix fio.rmtree to work with non empty dirs

Fix 'fio.rmtree' to remove a non empty directories.
And update test.

Closes #3258
parent d2e70f18
No related branches found
No related tags found
No related merge requests found
......@@ -382,8 +382,12 @@ fio.rmtree = function(path)
for i, f in ipairs(ls) do
local tmppath = fio.pathjoin(path, f)
local st = fio.stat(tmppath)
if st and st:is_dir() then
st, err = fio.rmtree(tmppath)
if st then
if st:is_dir() then
st, err = fio.rmtree(tmppath)
else
st, err = fio.unlink(tmppath)
end
if err ~= nil then
return nil, err
end
......
......@@ -413,6 +413,27 @@ fio.rmdir(dir2)
- false
- 'fio: No such file or directory'
...
-- gh-3258 rmtree should remove directories with files
fio.mktree('tmp2/tmp3/tmp4')
---
- true
...
fh = fio.open('tmp2/tmp3/tmp4/tmp.txt', {'O_RDWR', 'O_CREAT'})
---
...
fh:close()
---
- true
...
fio.rmtree('tmp2')
---
- true
...
fio.stat('tmp2')
---
- null
- 'fio: No such file or directory'
...
fio.rmdir(tmpdir)
---
- true
......
......@@ -131,6 +131,14 @@ fio.rmdir(dir2)
{ fio.unlink(file1), fio.unlink(file2), fio.unlink(file3), fio.unlink(file4) }
{ fio.unlink(file1), fio.unlink(file2), fio.unlink(file3), fio.unlink(file4) }
-- gh-3258 rmtree should remove directories with files
fio.mktree('tmp2/tmp3/tmp4')
fh = fio.open('tmp2/tmp3/tmp4/tmp.txt', {'O_RDWR', 'O_CREAT'})
fh:close()
fio.rmtree('tmp2')
fio.stat('tmp2')
fio.rmdir(tmpdir)
fio.rmdir(tmpdir)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment