diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2021-01-29 12:29:37 +0300 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2021-01-31 10:14:59 +0300 |
commit | 480134cbb2d4141be31901028078d18a2701ea6b (patch) | |
tree | 88c388e06eb8240e25c2f89f0ee0822f90a553fd /lua | |
parent | 05555c6913285deeacc525560c7e773b2e42f112 (diff) |
chore(dir) reduce scopes and fix indentation
Diffstat (limited to 'lua')
-rw-r--r-- | lua/pl/dir.lua | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/lua/pl/dir.lua b/lua/pl/dir.lua index 56d084c..4e3922e 100644 --- a/lua/pl/dir.lua +++ b/lua/pl/dir.lua @@ -349,43 +349,45 @@ function dir.rmtree(fullpath) return true end -local dirpat -if path.is_windows then - dirpat = '(.+)\\[^\\]+$' -else - dirpat = '(.+)/[^/]+$' -end - -local _makepath -function _makepath(p) - -- windows root drive case - if p:find '^%a:[\\]*$' then - return true - end - if not path.isdir(p) then - local subp = p:match(dirpat) - local ok, err = _makepath(subp) - if not ok then return nil, err end - return mkdir(p) - else - return true - end -end ---- create a directory path. --- This will create subdirectories as necessary! --- @string p A directory path --- @return true on success, nil + errormsg on failure --- @raise failure to create -function dir.makepath (p) - assert_string(1,p) - if path.is_windows then - p = p:gsub("/", "\\") - end - return _makepath(path.abspath(p)) +do + local dirpat + if path.is_windows then + dirpat = '(.+)\\[^\\]+$' + else + dirpat = '(.+)/[^/]+$' + end + + local _makepath + function _makepath(p) + -- windows root drive case + if p:find '^%a:[\\]*$' then + return true + end + if not path.isdir(p) then + local subp = p:match(dirpat) + local ok, err = _makepath(subp) + if not ok then return nil, err end + return mkdir(p) + else + return true + end + end + + --- create a directory path. + -- This will create subdirectories as necessary! + -- @string p A directory path + -- @return true on success, nil + errormsg on failure + -- @raise failure to create + function dir.makepath (p) + assert_string(1,p) + if path.is_windows then + p = p:gsub("/", "\\") + end + return _makepath(path.abspath(p)) + end end - --- clone a directory tree. Will always try to create a new directory structure -- if necessary. -- @string path1 the base path of the source tree |