Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] lua: fix fio.rmtree to work with non empty dirs
@ 2018-07-16 16:15 Konstantin Belyavskiy
  2018-07-18  3:43 ` [tarantool-patches] " Alexander Turenko
  0 siblings, 1 reply; 5+ messages in thread
From: Konstantin Belyavskiy @ 2018-07-16 16:15 UTC (permalink / raw)
  To: tarantool-patches

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)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH] lua: fix fio.rmtree to work with non empty dirs
  2018-07-16 16:15 [tarantool-patches] [PATCH] lua: fix fio.rmtree to work with non empty dirs Konstantin Belyavskiy
@ 2018-07-18  3:43 ` Alexander Turenko
  2018-07-23 17:27   ` [tarantool-patches] Re[2]: [tarantool-patches] " Konstantin Belyavskiy
  2018-07-26 21:32   ` [tarantool-patches] " Konstantin Osipov
  0 siblings, 2 replies; 5+ messages in thread
From: Alexander Turenko @ 2018-07-18  3:43 UTC (permalink / raw)
  To: Konstantin Belyavskiy; +Cc: tarantool-patches

Hi Kostya!

The patch looks good for me except one tiny comment.

WBR, Alexander Turenko.

> 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')
> +

I think it would be good to check that the directory really disappears
(via fio.listdir()).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re[2]: [tarantool-patches] [PATCH] lua: fix fio.rmtree to work with non empty dirs
  2018-07-18  3:43 ` [tarantool-patches] " Alexander Turenko
@ 2018-07-23 17:27   ` Konstantin Belyavskiy
  2018-07-24  9:28     ` [tarantool-patches] Re: Re[2]: " Alexander Turenko
  2018-07-26 21:32   ` [tarantool-patches] " Konstantin Osipov
  1 sibling, 1 reply; 5+ messages in thread
From: Konstantin Belyavskiy @ 2018-07-23 17:27 UTC (permalink / raw)
  To: Alexander Turenko; +Cc: tarantool-patches

[-- Attachment #1: Type: text/plain, Size: 941 bytes --]

Thanks for review, now check directory absence with fio.stat()

>Среда, 18 июля 2018, 6:43 +03:00 от Alexander Turenko <alexander.turenko@tarantool.org>:
>
>Hi Kostya!
>
>The patch looks good for me except one tiny comment.
>
>WBR, Alexander Turenko.
>
>> 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')
>> +
>
>I think it would be good to check that the directory really disappears
>(via fio.listdir()).


Best regards,
Konstantin Belyavskiy
k.belyavskiy@tarantool.org

[-- Attachment #2: Type: text/html, Size: 1567 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: Re[2]: [PATCH] lua: fix fio.rmtree to work with non empty dirs
  2018-07-23 17:27   ` [tarantool-patches] Re[2]: [tarantool-patches] " Konstantin Belyavskiy
@ 2018-07-24  9:28     ` Alexander Turenko
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Turenko @ 2018-07-24  9:28 UTC (permalink / raw)
  To: Konstantin Belyavskiy; +Cc: tarantool-patches

Hi,

LGTM.

WBR, Alexander Turenko.

On Mon, Jul 23, 2018 at 08:27:47PM +0300, Konstantin Belyavskiy wrote:
>    Thanks for review, now check directory absence with fio.stat()
> 
>      Среда, 18 июля 2018, 6:43 +03:00 от Alexander Turenko
>      <alexander.turenko@tarantool.org>:
> 
>    Hi Kostya!
>    The patch looks good for me except one tiny comment.
>    WBR, Alexander Turenko.
>    > 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')
>    > +
>    I think it would be good to check that the directory really disappears
>    (via fio.listdir()).
> 
>    Best regards,
>    Konstantin Belyavskiy
>    k.belyavskiy@tarantool.org

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH] lua: fix fio.rmtree to work with non empty dirs
  2018-07-18  3:43 ` [tarantool-patches] " Alexander Turenko
  2018-07-23 17:27   ` [tarantool-patches] Re[2]: [tarantool-patches] " Konstantin Belyavskiy
@ 2018-07-26 21:32   ` Konstantin Osipov
  1 sibling, 0 replies; 5+ messages in thread
From: Konstantin Osipov @ 2018-07-26 21:32 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Konstantin Belyavskiy

* Alexander Turenko <alexander.turenko@tarantool.org> [18/07/18 09:46]:
> Hi Kostya!
> 
> The patch looks good for me except one tiny comment.
> 

I pushed an updated patch (it was not sent to this list), but
contains a fix for this review comment.

> WBR, Alexander Turenko.
> 
> > 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')
> > +
> 
> I think it would be good to check that the directory really disappears
> (via fio.listdir()).

-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-07-26 21:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-16 16:15 [tarantool-patches] [PATCH] lua: fix fio.rmtree to work with non empty dirs Konstantin Belyavskiy
2018-07-18  3:43 ` [tarantool-patches] " Alexander Turenko
2018-07-23 17:27   ` [tarantool-patches] Re[2]: [tarantool-patches] " Konstantin Belyavskiy
2018-07-24  9:28     ` [tarantool-patches] Re: Re[2]: " Alexander Turenko
2018-07-26 21:32   ` [tarantool-patches] " Konstantin Osipov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox