@@ -29,7 +29,7 @@ def initialize(options = {})
2929 begin
3030 max_revisions = ProcessManager ::Config . config [ :max_revisions ]
3131 @archives_to_retain = max_revisions . nil? ? ARCHIVES_TO_RETAIN : Integer ( max_revisions )
32- if @archives_to_retain < 0
32+ if @archives_to_retain < 1
3333 raise ArgumentError
3434 end
3535 rescue ArgumentError
@@ -68,7 +68,7 @@ def command_method(command_name)
6868 end
6969
7070 command "DownloadBundle" do |cmd , deployment_spec |
71- cleanup_old_archives ( deployment_spec . deployment_group_id )
71+ cleanup_old_archives ( deployment_spec )
7272 log ( :debug , "Executing DownloadBundle command for execution #{ cmd . deployment_execution_id } " )
7373
7474 case deployment_spec . revision_source
@@ -336,15 +336,17 @@ def update_last_successful_install(deployment_spec)
336336 end
337337
338338 private
339- def cleanup_old_archives ( deployment_group )
339+ def cleanup_old_archives ( deployment_spec )
340+ deployment_group = deployment_spec . deployment_group_id
340341 deployment_archives = Dir . entries ( File . join ( ProcessManager ::Config . config [ :root_dir ] , deployment_group ) )
341342 # remove . and ..
342343 deployment_archives . delete ( "." )
343344 deployment_archives . delete ( ".." )
344345
345346 full_path_deployment_archives = deployment_archives . map { |f | File . join ( ProcessManager ::Config . config [ :root_dir ] , deployment_group , f ) }
347+ full_path_deployment_archives . delete ( deployment_root_dir ( deployment_spec ) )
346348
347- extra = full_path_deployment_archives . size - @archives_to_retain
349+ extra = full_path_deployment_archives . size - @archives_to_retain + 1
348350 return unless extra > 0
349351
350352 # Never remove the last successful deployment
0 commit comments