File tree Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -273,17 +273,27 @@ def user
273273 '/var/spool/cron'
274274 end
275275
276+ # Return the directory holding crontab files stored on the local system.
277+ #
278+ # @api private
279+ def self . crontab_dir
280+ CRONTAB_DIR
281+ end
282+
276283 # Yield the names of all crontab files stored on the local system.
277284 #
278- # @note Ignores files that are not writable for the puppet process.
285+ # @note Ignores files that are not writable for the puppet process and hidden
286+ # files that start with .keep
279287 #
280288 # @api private
281289 def self . enumerate_crontabs
282290 Puppet . debug "looking for crontabs in #{ CRONTAB_DIR } "
283291 return unless File . readable? ( CRONTAB_DIR )
284292 Dir . foreach ( CRONTAB_DIR ) do |file |
285- path = "#{ CRONTAB_DIR } /#{ file } "
286- yield ( file ) if File . file? ( path ) && File . writable? ( path )
293+ path = File . join ( CRONTAB_DIR , file )
294+ # Gentoo creates .keep_PACKAGE-SLOT files to make sure the directory is not
295+ # removed
296+ yield ( file ) if File . file? ( path ) && File . writable? ( path ) && !file . start_with? ( '.keep_' )
287297 end
288298 end
289299
Original file line number Diff line number Diff line change @@ -202,4 +202,43 @@ def compare_crontab_record(have, want)
202202 end
203203 end
204204 end
205+
206+ context '#enumerate_crontabs' do
207+ before ( :each ) do
208+ File . expects ( :readable? ) . with ( subject . crontab_dir ) . returns ( true )
209+ Dir . expects ( :foreach ) . with ( subject . crontab_dir ) . multiple_yields ( *files )
210+ end
211+
212+ context 'only a hidden file' do
213+ let ( :files ) { [ '.keep_cronbase-0' ] }
214+
215+ before ( :each ) do
216+ files . each do |filename |
217+ path = File . join ( subject . crontab_dir , filename )
218+ File . expects ( :file? ) . with ( path ) . returns ( true )
219+ File . expects ( :writable? ) . with ( path ) . returns ( true )
220+ end
221+ end
222+
223+ it 'ignores .keep_* files' do
224+ expect { |b | described_class . enumerate_crontabs ( &b ) } . not_to yield_control
225+ end
226+ end
227+
228+ context 'multiple files' do
229+ let ( :files ) { [ 'myuser' , '.keep_cronbase-0' ] }
230+
231+ before ( :each ) do
232+ files . each do |filename |
233+ path = File . join ( subject . crontab_dir , filename )
234+ File . expects ( :file? ) . with ( path ) . returns ( true )
235+ File . expects ( :writable? ) . with ( path ) . returns ( true )
236+ end
237+ end
238+
239+ it 'ignores .keep_* files' do
240+ expect { |b | described_class . enumerate_crontabs ( &b ) } . to yield_control . once
241+ end
242+ end
243+ end
205244end
You can’t perform that action at this time.
0 commit comments