aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2024-09-02 17:57:25 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-10-21 13:30:51 -0300
commit6c458fbfbf1c542036af2adf11f4311b0413f663 (patch)
treec28cbbb3dc7b1ec7dd2b2af015ddfef2986d3906
parent101711ad9e691f83a03c309fd7b4f093c52dee36 (diff)
downloadluarocks-6c458fbfbf1c542036af2adf11f4311b0413f663.tar.gz
luarocks-6c458fbfbf1c542036af2adf11f4311b0413f663.tar.bz2
luarocks-6c458fbfbf1c542036af2adf11f4311b0413f663.zip
fs: more consistent function signatures
-rw-r--r--src/luarocks/fs.d.tl4
-rw-r--r--src/luarocks/fs/lua.lua11
-rw-r--r--src/luarocks/fs/unix/tools.lua16
3 files changed, 18 insertions, 13 deletions
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl
index 580f7c3f..45044b72 100644
--- a/src/luarocks/fs.d.tl
+++ b/src/luarocks/fs.d.tl
@@ -15,7 +15,7 @@ local record fs
15 is_file: function(file: string): boolean 15 is_file: function(file: string): boolean
16 current_dir: function(): string 16 current_dir: function(): string
17 list_dir: function(?string): {string} 17 list_dir: function(?string): {string}
18 delete: function(string) 18 delete: function(string): boolean, string
19 -- signing 19 -- signing
20 is_tool_available: function(string, string): string, string 20 is_tool_available: function(string, string): string, string
21 execute: function(...: string): boolean, string, string 21 execute: function(...: string): boolean, string, string
@@ -57,7 +57,7 @@ local record fs
57 wrap_script: function(string, string, string, string, string): boolean, string 57 wrap_script: function(string, string, string, string, string): boolean, string
58 is_lua: function(string): boolean 58 is_lua: function(string): boolean
59 copy_binary: function(string, string): boolean, string 59 copy_binary: function(string, string): boolean, string
60 move: function(string, string, string): boolean, string 60 move: function(string, string, perms?: string): boolean, string
61 -- writer 61 -- writer
62 replace_file: function(string, string): boolean, string 62 replace_file: function(string, string): boolean, string
63 get_md5: function(string): string, string 63 get_md5: function(string): string, string
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 02d9353a..0f1ee55e 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -562,14 +562,15 @@ end
562local function recursive_delete(name) 562local function recursive_delete(name)
563 local ok = os.remove(name) 563 local ok = os.remove(name)
564 if ok then return true end 564 if ok then return true end
565 local pok, ok, err = pcall(function() 565 local pok, err
566 pok, ok, err = pcall(function()
566 for file in lfs.dir(name) do 567 for file in lfs.dir(name) do
567 if file ~= "." and file ~= ".." then 568 if file ~= "." and file ~= ".." then
568 local ok, err = recursive_delete(dir.path(name, file)) 569 ok, err = recursive_delete(dir.path(name, file))
569 if not ok then return nil, err end 570 if not ok then return nil, err end
570 end 571 end
571 end 572 end
572 local ok, err = lfs.rmdir(name) 573 ok, err = lfs.rmdir(name)
573 return ok, (not ok) and err 574 return ok, (not ok) and err
574 end) 575 end)
575 if pok then 576 if pok then
@@ -581,10 +582,10 @@ end
581 582
582--- Delete a file or a directory and all its contents. 583--- Delete a file or a directory and all its contents.
583-- @param name string: Pathname of source 584-- @param name string: Pathname of source
584-- @return nil 585-- @return true on success, or nil and an error message on failure
585function fs_lua.delete(name) 586function fs_lua.delete(name)
586 name = dir.normalize(name) 587 name = dir.normalize(name)
587 recursive_delete(name) 588 return recursive_delete(name)
588end 589end
589 590
590--- Internal implementation function for fs.dir. 591--- Internal implementation function for fs.dir.
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index f1513820..2127aed6 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -92,12 +92,16 @@ function tools.copy_contents(src, dest)
92end 92end
93--- Delete a file or a directory and all its contents. 93--- Delete a file or a directory and all its contents.
94-- For safety, this only accepts absolute paths. 94-- For safety, this only accepts absolute paths.
95-- @param arg string: Pathname of source 95-- @param pathname string: Pathname of source
96-- @return nil 96-- @return true on success, nil and an error on failure
97function tools.delete(arg) 97function tools.delete(pathname)
98 assert(arg) 98 assert(pathname)
99 assert(arg:sub(1,1) == "/") 99 assert(pathname:sub(1,1) == "/")
100 fs.execute_quiet(vars.RM, "-rf", arg) 100 if fs.execute_quiet(vars.RM, "-rf", pathname) then
101 return true
102 else
103 return nil, "failed deleting " .. pathname
104 end
101end 105end
102 106
103--- Recursively scan the contents of a directory. 107--- Recursively scan the contents of a directory.