get rid of the symlink thing and just recreate the config directory each time
This commit is contained in:
parent
d373738451
commit
2770636def
@ -9,7 +9,7 @@ GEM
|
||||
specs:
|
||||
autotest (4.4.2)
|
||||
diff-lcs (1.1.2)
|
||||
mocha (0.9.9)
|
||||
mocha (0.9.10)
|
||||
rake
|
||||
nokogiri (1.4.3.1)
|
||||
rainbow (1.1)
|
||||
|
@ -92,15 +92,17 @@ module Apache
|
||||
def build(target, &block)
|
||||
config = build_and_return(&block)
|
||||
|
||||
if !disabled?
|
||||
FileUtils.mkdir_p File.split(target).first
|
||||
File.open(target, 'w') { |file| file.puts generate_config_file(config) * "\n" }
|
||||
@was_written = true
|
||||
end
|
||||
|
||||
config
|
||||
end
|
||||
|
||||
# If included in a configuration, will not generate the symlink in the Rake task
|
||||
def disable_symlink!
|
||||
# If included in a configuration, will not generate the config file in the Rake task
|
||||
def disable!
|
||||
@is_disabled = true
|
||||
end
|
||||
|
||||
@ -113,9 +115,7 @@ module Apache
|
||||
end
|
||||
|
||||
def generate_config_file(config)
|
||||
output = [ "# Generated by apache-config-generator #{Time.now.to_s}", config ]
|
||||
output.unshift('# disabled') if @is_disabled
|
||||
output.flatten
|
||||
[ "# Generated by apache-config-generator #{Time.now.to_s}", config ].flatten
|
||||
end
|
||||
|
||||
# Reset the current settings
|
||||
|
@ -27,6 +27,7 @@ namespace :apache do
|
||||
|
||||
Apache::Config.rotate_logs_path = config[:rotate_logs_path]
|
||||
|
||||
FileUtils.rm_rf config[:destination_path]
|
||||
FileUtils.mkdir_p config[:destination_path]
|
||||
Dir.chdir config[:destination_path]
|
||||
|
||||
@ -47,8 +48,6 @@ namespace :apache do
|
||||
puts output
|
||||
end
|
||||
end
|
||||
|
||||
symlink_configs!
|
||||
end
|
||||
|
||||
desc "List all possible environments"
|
||||
|
@ -28,7 +28,7 @@ module Apache
|
||||
end
|
||||
|
||||
def config_paths!
|
||||
[ :source, :destination, :symlink ].each do |which|
|
||||
[ :source, :destination ].each do |which|
|
||||
begin
|
||||
@config[:"#{which}_path"] = File.expand_path(@config[which])
|
||||
rescue StandardError
|
||||
@ -39,8 +39,6 @@ module Apache
|
||||
end
|
||||
|
||||
def get_environments
|
||||
config[:source_path] = File.expand_path(config[:source])
|
||||
|
||||
Dir[File.join(config[:source_path], '**', '*.rb')].collect { |file|
|
||||
File.readlines(file).find_all { |line| line[%r{(if_environment|build_if)}] }.collect { |line| line.scan(%r{:[a-z_]+}) }
|
||||
}.flatten.uniq.sort.collect { |name| name[1..-1] }
|
||||
@ -60,23 +58,6 @@ module Apache
|
||||
puts "rake apache:default[#{get_environments.first}]"
|
||||
exit 1
|
||||
end
|
||||
|
||||
def symlink_configs!
|
||||
raise Errno::ENOENT if !File.directory?(config[:destination_path])
|
||||
|
||||
FileUtils.rm_rf(config[:symlink_path])
|
||||
FileUtils.mkdir_p(config[:symlink_path])
|
||||
|
||||
Dir[File.join(config[:destination_path], '**/*')].find_all { |file| File.file?(file) }.each do |file|
|
||||
if line = File.read(file).first
|
||||
if !line['# disabled']
|
||||
target = file.gsub(config[:destination_path], config[:symlink_path])
|
||||
FileUtils.mkdir_p(File.split(target).first)
|
||||
FileUtils.ln_sf(file, target)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,3 @@
|
||||
source: "source"
|
||||
destination: "conf.d-original"
|
||||
symlink: "conf.d"
|
||||
destination: "conf.d"
|
||||
rotate_logs_path: '/path/to/apache/bin/rotatelogs'
|
||||
|
@ -33,32 +33,38 @@ describe Apache::Config, "builds configurations" do
|
||||
end
|
||||
end
|
||||
|
||||
describe '.disable_symlink!' do
|
||||
describe '.disable!' do
|
||||
context 'is enabled by default' do
|
||||
it { apache.instance_variable_get(:@is_disabled).should be_false }
|
||||
it { apache.disabled?.should be_false }
|
||||
|
||||
context 'writes config' do
|
||||
before {
|
||||
FileUtils.expects(:mkdir_p).once
|
||||
File.expects(:open).once
|
||||
apache.build("here") { cats }
|
||||
}
|
||||
|
||||
it { apache.written?.should == true }
|
||||
end
|
||||
end
|
||||
|
||||
context 'disable' do
|
||||
before { apache.disable_symlink! }
|
||||
before { apache.disable! }
|
||||
|
||||
it { apache.instance_variable_get(:@is_disabled).should be_true }
|
||||
it { apache.disabled?.should be_true }
|
||||
|
||||
context 'does not write config' do
|
||||
before {
|
||||
FileUtils.expects(:mkdir_p).never
|
||||
File.expects(:open).never
|
||||
apache.build("here") { disable!; cats }
|
||||
}
|
||||
|
||||
it { apache.written?.should == false }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.generate_config_file' do
|
||||
subject { apache.generate_config_file(%w{config}) }
|
||||
|
||||
context 'with symlink' do
|
||||
its(:first) { should_not == '# disabled' }
|
||||
end
|
||||
|
||||
context 'without symlink' do
|
||||
before { apache.disable_symlink! }
|
||||
|
||||
its(:first) { should == '# disabled' }
|
||||
end
|
||||
end
|
||||
|
||||
it "should handle indent" do
|
||||
|
@ -6,14 +6,12 @@ describe Apache::Rake::Support do
|
||||
|
||||
let(:source) { '/source' }
|
||||
let(:destination) { '/destination/available' }
|
||||
let(:symlink) { '/destination/enabled' }
|
||||
|
||||
describe 'config_paths!' do
|
||||
before {
|
||||
@config = {
|
||||
:source => 'cats',
|
||||
:destination => 'dogs',
|
||||
:symlink => 'cows'
|
||||
:destination => 'dogs'
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,79 +19,5 @@ describe Apache::Rake::Support do
|
||||
|
||||
its([:source_path]) { should == File.expand_path('cats') }
|
||||
its([:destination_path]) { should == File.expand_path('dogs') }
|
||||
its([:symlink_path]) { should == File.expand_path('cows') }
|
||||
end
|
||||
|
||||
describe 'symlink_configs!' do
|
||||
before {
|
||||
@config = {
|
||||
:source_path => source,
|
||||
:destination_path => destination,
|
||||
:symlink_path => symlink
|
||||
}
|
||||
}
|
||||
|
||||
subject { symlink_configs! }
|
||||
|
||||
context 'source does not exist' do
|
||||
before { File.expects(:directory?).with(destination).returns(false) }
|
||||
|
||||
it { expect { subject }.to raise_error(Errno::ENOENT) }
|
||||
end
|
||||
|
||||
context 'source does exist' do
|
||||
before {
|
||||
File.expects(:directory?).with(destination).returns(true)
|
||||
FileUtils.expects(:rm_rf).with(symlink)
|
||||
FileUtils.expects(:mkdir_p).with(symlink)
|
||||
Dir.expects(:[]).with(File.join(destination, '**/*')).returns(dir_return)
|
||||
}
|
||||
|
||||
context 'with no configs' do
|
||||
let(:dir_return) { [] }
|
||||
|
||||
before { FileUtils.expects(:ln_sf).never }
|
||||
|
||||
it { subject }
|
||||
end
|
||||
|
||||
context 'with one config' do
|
||||
let(:filename) { File.join(destination, 'dogs/cats') }
|
||||
let(:dir_return) { [ filename ] }
|
||||
|
||||
before { File.expects(:file?).with(filename).returns(is_file_result) }
|
||||
|
||||
context 'is a directory' do
|
||||
let(:is_file_result) { false }
|
||||
|
||||
it { subject }
|
||||
end
|
||||
|
||||
context 'is a file' do
|
||||
let(:is_file_result) { true }
|
||||
|
||||
before { File.expects(:read).with(filename).returns(read_result) }
|
||||
|
||||
context 'config should not be symlinked' do
|
||||
let(:read_result) { ['# disabled'] }
|
||||
|
||||
before { FileUtils.expects(:ln_sf).never }
|
||||
|
||||
it { subject }
|
||||
end
|
||||
|
||||
context 'config should be symlinked' do
|
||||
let(:read_result) { ['# whatever'] }
|
||||
|
||||
before {
|
||||
FileUtils.expects(:mkdir_p).with(File.join(symlink, 'dogs'))
|
||||
FileUtils.expects(:ln_sf).with(filename, filename.gsub(destination, symlink))
|
||||
}
|
||||
|
||||
it { subject }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user