Skip to content

Fix #365 producing huge packages because of hard links #623

Closed
wants to merge 1 commit into from
+13 −1
View
14 lib/fpm/util.rb
@@ -155,7 +155,19 @@ def copy_entry(src, dst)
when 'directory'
FileUtils.mkdir(dst) unless File.exists? dst
else
- FileUtils.copy_entry(src, dst)
+ # if the file with the same dev and inode has been copied already -
+ # hard link it's copy to `dst`, otherwise make an actual copy
+ st = File.stat(src)
@jordansissel
Owner
jordansissel added a note Mar 7, 2014

I wonder if File.lstat() is more correct here (otherwise we're following a symlink which may not be waht we want to do)

I'll fiddle with this post-merge and try to write a test for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if copied_entry = copied_entries[[st.dev, st.ino]]
+ FileUtils.ln(copied_entry, dst)
+ else
+ FileUtils.copy_entry(src, dst)
+ copied_entries.store([st.dev, st.ino], dst)
+ end
end
end
+
+ def copied_entries
+ @copied_entries ||= {}
+ end
end # module FPM::Util
Something went wrong with that request. Please try again.