From 1d3536d26c6f5280ce288a14ff0182999dff1f0b Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 23 Feb 2010 09:16:05 +0000 Subject: Added fs.copy_properties function and call it in copy_file. --- fs.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs.lua b/fs.lua index 63b996d..6f89593 100644 --- a/fs.lua +++ b/fs.lua @@ -61,6 +61,17 @@ function create_file ( path ) return is_file(path) end +-- Copies the permissions and ownership of one file to another (if they exist and are the same type) +function copy_properties(source, dest) + if posix.stat(source or "", "type") == posix.stat(dest or "", "type") then + local stats = posix.stat(source) + posix.chmod(dest, stats.mode) + posix.chown(dest, stats.uid, stats.gid) + return true + end + return false +end + -- Copies a file to a directory or new filename (creating the directory if necessary) -- fails if new file is already a directory (this is different than cp function) -- if newpath ends in "/", will treat as a directory @@ -76,6 +87,7 @@ function copy_file(oldpath, newpath) new:write(old:read("*a")) new:close() old:close() + copy_properties(oldpath, newpath) return is_file(newpath) end -- cgit v1.2.3