diff options
author | Ted Trask <ttrask01@yahoo.com> | 2010-02-23 09:16:05 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2010-02-23 09:16:05 +0000 |
commit | 1d3536d26c6f5280ce288a14ff0182999dff1f0b (patch) | |
tree | 90dcc0c1b276f93876c90e0437b1d5e5b02b7222 | |
parent | d9582fe377f86ad59f742a422e565c0c768ba617 (diff) | |
download | acf-lib-1d3536d26c6f5280ce288a14ff0182999dff1f0b.tar.bz2 acf-lib-1d3536d26c6f5280ce288a14ff0182999dff1f0b.tar.xz |
Added fs.copy_properties function and call it in copy_file.
-rw-r--r-- | fs.lua | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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 |