From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 66644239F0 for ; Mon, 16 Jul 2018 12:15:47 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lsSy74rV1G7z for ; Mon, 16 Jul 2018 12:15:47 -0400 (EDT) Received: from smtp62.i.mail.ru (smtp62.i.mail.ru [217.69.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id A981D23553 for ; Mon, 16 Jul 2018 12:15:46 -0400 (EDT) Received: by smtp62.i.mail.ru with esmtpa (envelope-from ) id 1ff6A3-0000LT-Ql for tarantool-patches@freelists.org; Mon, 16 Jul 2018 19:15:44 +0300 From: Konstantin Belyavskiy Subject: [tarantool-patches] [PATCH] lua: fix fio.rmtree to work with non empty dirs Date: Mon, 16 Jul 2018 19:15:43 +0300 Message-Id: <20180716161543.14753-1-k.belyavskiy@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Fix 'fio.rmtree' to remove a non empty directories. And update test. Closes #3258 --- Ticket: https://github.com/tarantool/tarantool/issues/3258 Branch: https://github.com/tarantool/tarantool/tree/kbelyavs/gh-3258-fix-fio-rmtree src/lua/fio.lua | 8 ++++++-- test/app/fio.result | 16 ++++++++++++++++ test/app/fio.test.lua | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/lua/fio.lua b/src/lua/fio.lua index 3fda6e532..d5531c154 100644 --- a/src/lua/fio.lua +++ b/src/lua/fio.lua @@ -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 diff --git a/test/app/fio.result b/test/app/fio.result index 6c4609855..d985b688b 100644 --- a/test/app/fio.result +++ b/test/app/fio.result @@ -413,6 +413,22 @@ 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.rmdir(tmpdir) --- - true diff --git a/test/app/fio.test.lua b/test/app/fio.test.lua index 0850413d9..14e0fb72c 100644 --- a/test/app/fio.test.lua +++ b/test/app/fio.test.lua @@ -131,6 +131,13 @@ 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.rmdir(tmpdir) fio.rmdir(tmpdir) -- 2.14.3 (Apple Git-98)