summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2010-02-23 09:27:20 +0000
committerTed Trask <ttrask01@yahoo.com>2010-02-23 09:27:20 +0000
commitcad408ec98e566da75775bfc735b260e9adeec8c (patch)
tree6d7bf97bdcdc536f087604fbbc916774ec23cbf9
parentb2b8ac87e45257215fa9642858a3bc5903b160e6 (diff)
downloadacf-core-cad408ec98e566da75775bfc735b260e9adeec8c.tar.bz2
acf-core-cad408ec98e566da75775bfc735b260e9adeec8c.tar.xz
Added fs.copy_properties and fixed fs.copy_file and modelfunction.write_file_with_audit to keep file properties.
-rw-r--r--lib/fs.lua12
-rw-r--r--lib/modelfunctions.lua1
2 files changed, 13 insertions, 0 deletions
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)