From 61ef39426b32665c0180c469e53152356a6477db Mon Sep 17 00:00:00 2001 From: f <f@sutty.nl> Date: Sat, 2 May 2020 12:21:53 -0300 Subject: [PATCH] remove files from previous builds --- lib/jekyll/static_file.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb index a2a9ee7..d60d56c 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 -- GitLab