[tarantool-patches] Re: [PATCH] Proper error handling for fio.mktree

Kirill Yukhin kyukhin at tarantool.org
Tue Sep 17 15:18:24 MSK 2019


Hello,

On 17 Sep 11:23, Maria wrote:
> Method fio.mktree used to create given path

Nit: is used

> unconditionally - without checking whether
> it was a directory or something else. This

Nit: if it was

> way led to inappropriate error messages or

Nit: This led

> even inconsistent behavior. Now we check the

Nit: Now check

> type of a given path.
> 
> Closes #4439
> 
> Issue:
> https://github.com/tarantool/tarantool/issues/4439
> Branch:
> https://github.com/tarantool/tarantool/tree/eljashm/gh-4439-error-handling-fio.mktree
> ---
>  src/lua/fio.lua       | 8 +++++++-
>  test/app/fio.test.lua | 6 ++++++
>  2 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lua/fio.lua b/src/lua/fio.lua
> index 321ae8b2d..a3a8ddc10 100644
> --- a/src/lua/fio.lua
> +++ b/src/lua/fio.lua
> @@ -360,14 +361,19 @@ fio.mktree = function(path, mode)
>      local current_dir = "/"
>      for i, dir in ipairs(dirs) do
>          current_dir = fio.pathjoin(current_dir, dir)
> -        if not fio.stat(current_dir) then
> +        local stat = fio.stat(current_dir)
> +        if stat == nil then
>              local st, err = fio.mkdir(current_dir, mode)
>              if err ~= nil  then
>                  return false, string.format("Error creating directory %s: %s",
>                      current_dir, tostring(err))
>              end
> +        elseif not stat:is_dir() then
> +            return false, string.format("Error creating directory %s: %s",
> +                current_dir, errno.strerror(errno.EEXIST))
>          end
>      end
> +
>      return true

This is useless change. Please discard.

> diff --git a/test/app/fio.test.lua b/test/app/fio.test.lua
> index be735e4f3..56c957d8a 100644
> --- a/test/app/fio.test.lua
> +++ b/test/app/fio.test.lua
> @@ -468,3 +468,9 @@ fio.rmtree(1)
>  fio.copytree(nil, nil)
>  fio.copytree(nil, nil)
>  test_run:cmd("clear filter")
> +
> +--
> +-- gh-4439: mktree error handling fix - creation of existing file/directory
> +--
> +fio.mktree('/dev/null')
> +fio.mktree('/dev/null/dir')
> -- 
> 2.20.1 (Apple Git-117)

Please update .result file as well.

Otherwise, lgtm.

--
Regards, Kirill Yukhin




More information about the Tarantool-patches mailing list