From 196dea8289d126aaf9a011a15b348fde0d5159d5 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Sat, 8 Dec 2018 13:42:23 +0100 Subject: (MODULES-8603) Ignore .keep_* files On Gentoo there's always a .keep_- (e.g., .keep_cronbase-0) file inside the cron directory to ensure it's not removed with rmdir. Since usernames are very unlikely to start with .keep_, we can safely filter out these hidden files. --- spec/unit/provider/cron/crontab_spec.rb | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'spec/unit') diff --git a/spec/unit/provider/cron/crontab_spec.rb b/spec/unit/provider/cron/crontab_spec.rb index 031b3ae..796a4c2 100644 --- a/spec/unit/provider/cron/crontab_spec.rb +++ b/spec/unit/provider/cron/crontab_spec.rb @@ -202,4 +202,43 @@ describe Puppet::Type.type(:cron).provider(:crontab) do end end end + + context '#enumerate_crontabs' do + before(:each) do + File.expects(:readable?).with(subject.crontab_dir).returns(true) + Dir.expects(:foreach).with(subject.crontab_dir).multiple_yields(*files) + end + + context 'only a hidden file' do + let(:files) { ['.keep_cronbase-0'] } + + before(:each) do + files.each do |filename| + path = File.join(subject.crontab_dir, filename) + File.expects(:file?).with(path).returns(true) + File.expects(:writable?).with(path).returns(true) + end + end + + it 'ignores .keep_* files' do + expect { |b| described_class.enumerate_crontabs(&b) }.not_to yield_control + end + end + + context 'multiple files' do + let(:files) { ['myuser', '.keep_cronbase-0'] } + + before(:each) do + files.each do |filename| + path = File.join(subject.crontab_dir, filename) + File.expects(:file?).with(path).returns(true) + File.expects(:writable?).with(path).returns(true) + end + end + + it 'ignores .keep_* files' do + expect { |b| described_class.enumerate_crontabs(&b) }.to yield_control.once + end + end + end end -- cgit v1.2.3