Permalink
Browse files

Preserve file’s group and owner

  • Loading branch information...
1 parent 55ca7ac commit 9f46c17bf6423c2c799171dd6869391481b4c4ab @sorbits sorbits committed Sep 30, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 rmate
View
@@ -100,7 +100,12 @@ def handle_save(socket, variables, data)
File.link(path, backup_path) if File.exist? path
Tempfile.open("rmate", File.dirname(path)) do |temp|
temp.close(false)
- File.chmod(File.stat(path).mode, temp.path) if File.exist? path
+ if File.exists?(path)
+ if stat = File.stat(path)
+ File.chown(stat.uid, stat.gid, temp.path)
+ File.chmod(stat.mode, temp.path)
+ end
+ end
open(temp.path, 'wb') {|file| file << data }
File.rename(temp.path, path)
end

0 comments on commit 9f46c17

Please sign in to comment.