From abfc6b6ca8cbf492c5e8b5ff3434b92f69076125 Mon Sep 17 00:00:00 2001 From: hisham Date: Wed, 1 Jul 2009 15:36:35 +0000 Subject: add 'move' command git-svn-id: http://luarocks.org/svn/luarocks/trunk@36 9ca3f7c1-7366-0410-b1a3-b5c78f85698c --- src/luarocks/fs/lua.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 16af8ab1..91cabe51 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -454,6 +454,10 @@ end end +--------------------------------------------------------------------- +-- Other functions +--------------------------------------------------------------------- + --- Apply a patch. -- @param patchname string: The filename of the patch. function apply_patch(patchname, patchdata) @@ -466,6 +470,31 @@ function apply_patch(patchname, patchdata) end end +--- Move a file. +-- @param src string: Pathname of source +-- @param dest string: Pathname of destination +-- @return boolean or (boolean, string): true on success, false on failure, +-- plus an error message. +function move(src, dest) + assert(src and dest) + if fs.exists(dest) then + return false, "File already exists: "..dest + end + local ok, err = fs.copy(src, dest) + if not ok then + return false, err + end + ok = fs.delete(src) + if not ok then + return false, "Failed move: could not delete "..src.." after copy." + end + return true +end + +--------------------------------------------------------------------- +-- TODO These still reference external binaries +--------------------------------------------------------------------- + --- Unpack an archive. -- Extract the contents of an archive, detecting its format by -- filename extension. -- cgit v1.2.3-55-g6feb