diff options
author | Steven Barth <steven@midlink.org> | 2008-09-01 19:42:43 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-09-01 19:42:43 +0000 |
commit | 76f2e5ec1a5fb8ab6c6c575434cb873e5db5d7cb (patch) | |
tree | d87c150ccb64191c2415d0716d3b7d57d36f25c0 /libs | |
parent | 7cc8a68ba929db44fa8f5f299a61f8c86ee9465b (diff) |
Added luci.fs.copy and luci.fs.rename
Diffstat (limited to 'libs')
-rw-r--r-- | libs/core/luasrc/fs.lua | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libs/core/luasrc/fs.lua b/libs/core/luasrc/fs.lua index 56108db953..ea346ee595 100644 --- a/libs/core/luasrc/fs.lua +++ b/libs/core/luasrc/fs.lua @@ -24,8 +24,11 @@ limitations under the License. ]]-- -local posix = require "posix" local io = require "io" +local os = require "os" +local ltn12 = require "ltn12" +local posix = require "posix" + local type = type --- LuCI filesystem library. @@ -91,6 +94,25 @@ function writefile(filename, data) return true end +--- Copies a file. +-- @param source Source file +-- @param dest Destination +-- @return Boolean containing true on success or nil on error +function copy(source, dest) + return ltn12.pump.all( + ltn12.source.file(io.open(source)), + ltn12.sink.file(io.open(dest, "w")) + ) +end + +--- Renames a file. +-- @param source Source file +-- @param dest Destination +-- @return Boolean containing true on success or nil on error +function rename(source, dest) + return os.rename(source, dest) +end + --- Get the last modification time of given file path in Unix epoch format. -- @param path String containing the path of the file or directory to read -- @return Number containing the epoch time or nil on error |