Merge branch 'deletion_protection' of https://github.com/jasonroelofs/jekyll into jasonroelofs-deletion_protection
This commit is contained in:
commit
c23302f4fa
|
@ -70,6 +70,12 @@ module Jekyll
|
||||||
def setup
|
def setup
|
||||||
require 'classifier' if self.lsi
|
require 'classifier' if self.lsi
|
||||||
|
|
||||||
|
# Check that the destination dir isn't the source dir or a directory
|
||||||
|
# parent to the source dir.
|
||||||
|
if self.source =~ /^#{self.dest}/
|
||||||
|
raise FatalException.new "Destination directory cannot be or contain the Source directory."
|
||||||
|
end
|
||||||
|
|
||||||
# If safe mode is off, load in any Ruby files under the plugins
|
# If safe mode is off, load in any Ruby files under the plugins
|
||||||
# directory.
|
# directory.
|
||||||
unless self.safe
|
unless self.safe
|
||||||
|
@ -216,8 +222,8 @@ module Jekyll
|
||||||
def cleanup
|
def cleanup
|
||||||
# all files and directories in destination, including hidden ones
|
# all files and directories in destination, including hidden ones
|
||||||
dest_files = Set.new
|
dest_files = Set.new
|
||||||
Dir.glob(File.join(self.dest, "**", "*"), File::FNM_DOTMATCH) do |file|
|
Dir.glob(File.join(self.dest, "**", "*")) do |file|
|
||||||
dest_files << file unless file =~ /\/\.{1,2}$/
|
dest_files << file
|
||||||
end
|
end
|
||||||
|
|
||||||
# files to be written
|
# files to be written
|
||||||
|
|
|
@ -166,13 +166,33 @@ class TestSite < Test::Unit::TestCase
|
||||||
assert_equal files, @site.filter_entries(files)
|
assert_equal files, @site.filter_entries(files)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'error handling' do
|
||||||
|
should "raise if destination is included in source" do
|
||||||
|
stub(Jekyll).configuration do
|
||||||
|
Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => source_dir})
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_raise Jekyll::FatalException do
|
||||||
|
site = Site.new(Jekyll.configuration)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "raise if destination is source" do
|
||||||
|
stub(Jekyll).configuration do
|
||||||
|
Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => File.join(source_dir, "..")})
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_raise Jekyll::FatalException do
|
||||||
|
site = Site.new(Jekyll.configuration)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with orphaned files in destination' do
|
context 'with orphaned files in destination' do
|
||||||
setup do
|
setup do
|
||||||
clear_dest
|
clear_dest
|
||||||
@site.process
|
@site.process
|
||||||
# generate some orphaned files:
|
# generate some orphaned files:
|
||||||
# hidden file
|
|
||||||
File.open(dest_dir('.htpasswd'), 'w')
|
|
||||||
# single file
|
# single file
|
||||||
File.open(dest_dir('obsolete.html'), 'w')
|
File.open(dest_dir('obsolete.html'), 'w')
|
||||||
# single file in sub directory
|
# single file in sub directory
|
||||||
|
@ -183,7 +203,6 @@ class TestSite < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
FileUtils.rm_f(dest_dir('.htpasswd'))
|
|
||||||
FileUtils.rm_f(dest_dir('obsolete.html'))
|
FileUtils.rm_f(dest_dir('obsolete.html'))
|
||||||
FileUtils.rm_rf(dest_dir('qux'))
|
FileUtils.rm_rf(dest_dir('qux'))
|
||||||
FileUtils.rm_f(dest_dir('quux'))
|
FileUtils.rm_f(dest_dir('quux'))
|
||||||
|
@ -191,7 +210,6 @@ class TestSite < Test::Unit::TestCase
|
||||||
|
|
||||||
should 'remove orphaned files in destination' do
|
should 'remove orphaned files in destination' do
|
||||||
@site.process
|
@site.process
|
||||||
assert !File.exist?(dest_dir('.htpasswd'))
|
|
||||||
assert !File.exist?(dest_dir('obsolete.html'))
|
assert !File.exist?(dest_dir('obsolete.html'))
|
||||||
assert !File.exist?(dest_dir('qux'))
|
assert !File.exist?(dest_dir('qux'))
|
||||||
assert !File.exist?(dest_dir('quux'))
|
assert !File.exist?(dest_dir('quux'))
|
||||||
|
|
Loading…
Reference in New Issue