diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb index a2a9ee7f563828268d0f17c123a1217db2c4d084..d60d56cf9109d0990ed745e9ba6589b24236d7cd 100644 --- a/lib/jekyll/static_file.rb +++ b/lib/jekyll/static_file.rb @@ -6,12 +6,26 @@ module Jekyll # the file def write(dest) dest_path = destination(dest) - return if File.exist? dest_path + + # If the file exists but it's not a hardlink, we remove it and + # replace it with one. This is useful when migrating from a site + # already built without this plugin. + if File.exist? dest_path + return if hardlink? dest_path + FileUtils.rm dest_path + end self.class.mtimes[path] = mtime FileUtils.mkdir_p(File.dirname(dest_path)) FileUtils.ln(path, dest_path) end + + private + + # Verifies the path has hardlinks + def hardlink?(path) + File.stat(path).nlink > 1 + end end end