From 96efa9ed062e2a690534ac435f960a46f135b773 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Fri, 17 May 2013 17:45:51 +0200 Subject: [PATCH 1/2] delete old files that have been replaced by a directory Fixes #417. Replaces #1086, more logical code. --- lib/jekyll/site.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index e8b65135..2b70a6f3 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -270,7 +270,11 @@ module Jekyll files.each { |file| dirs << File.dirname(file) } files.merge(dirs) - obsolete_files = dest_files - files + # files that are replaced by dirs should be deleted + files_to_delete = Set.new + dirs.each { |dir| files_to_delete << dir if File.file?(dir) } + + obsolete_files = dest_files - files + files_to_delete FileUtils.rm_rf(obsolete_files.to_a) end From 45576a39a665ab354e9105f6abe2c829659e5e8c Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sat, 18 May 2013 22:30:03 +0200 Subject: [PATCH 2/2] test this fix with a cucumber feature --- features/create_sites.feature | 11 +++++++++++ features/step_definitions/jekyll_steps.rb | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/features/create_sites.feature b/features/create_sites.feature index cbdfb64b..4811cdbf 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -110,3 +110,14 @@ Feature: Create sites When I run jekyll Then the _site directory should exist And I should see "SomeDirective" in "_site/.htaccess" + + Scenario: File was replaced by a directory + Given I have a "test" file that contains "some stuff" + When I run jekyll + Then the _site directory should exist + When I delete the file "test" + Given I have a test directory + And I have a "test/index.html" file that contains "some other stuff" + When I run jekyll + Then the _site/test directory should exist + And I should see "some other stuff" in "_site/test/index.html" diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 75330738..4e68f9b8 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -140,6 +140,10 @@ When /^I change "(.*)" to contain "(.*)"$/ do |file, text| end end +When /^I delete the file "(.*)"$/ do |file| + File.delete(file) +end + Then /^the (.*) directory should exist$/ do |dir| assert File.directory?(dir), "The directory \"#{dir}\" does not exist" end