Skip to content

Commit

Permalink
- only set permissions/ownership/times if the source and destinations
Browse files Browse the repository at this point in the history
  aren't pointing at the same inode.
  • Loading branch information
jordansissel committed May 15, 2012
1 parent b410940 commit 823c510
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/fpm/package/dir.rb
Expand Up @@ -112,15 +112,20 @@ def copy(source, destination)
end # def copy

def copy_metadata(source, destination)
st = File::lstat(source)
File.utime(st.atime, st.mtime, destination)
source_stat = File::lstat(source)
dest_stat = File::lstat(destination)

# If this is a hard-link, there's no metadata to copy.
return if source_stat.ino == dest_stat.ino

File.utime(source_stat.atime, source_stat.mtime, destination)
begin
File.chown(st.uid, st.gid, destination)
File.chown(source_stat.uid, source_stat.gid, destination)
rescue Errno::EPERM
# clear setuid/setgid
File.chmod(st.mode & 01777, destination)
File.chmod(source_stat.mode & 01777, destination)
else
File.chmod(st.mode, destination)
File.chmod(source_stat.mode, destination)
end
end # def copy_metadata

Expand Down

0 comments on commit 823c510

Please sign in to comment.