From cad408ec98e566da75775bfc735b260e9adeec8c Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 23 Feb 2010 09:27:20 +0000 Subject: Added fs.copy_properties and fixed fs.copy_file and modelfunction.write_file_with_audit to keep file properties. --- lib/fs.lua | 12 ++++++++++++ lib/modelfunctions.lua | 1 + 2 files changed, 13 insertions(+) diff --git a/lib/fs.lua b/lib/fs.lua index 872e62a..cfc387a 100644 --- a/lib/fs.lua +++ b/lib/fs.lua @@ -77,6 +77,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 function copy_file(oldpath, newpath) @@ -90,6 +101,7 @@ function copy_file(oldpath, newpath) new:write(old:read("*a")) new:close() old:close() + copy_properties(oldpath, newpath) return is_file(newpath) end diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua index 70f1412..3a02bd5 100644 --- a/lib/modelfunctions.lua +++ b/lib/modelfunctions.lua @@ -205,6 +205,7 @@ function write_file_with_audit (self, path, str) end fs.write_file(tmpfile,str) + fs.copy_properties(path, tmpfile) if (type(pre) == "string" and #pre) then os.execute(pre) -- cgit v1.2.3