summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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)