diff --git a/CHANGELOG.md b/CHANGELOG.md index aa86c3a8..fc2299ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ https://github.com/capistrano/capistrano/compare/v3.7.0.beta1...HEAD * Your contribution here! +* Fix the removal of old releases `deploy:cleanup`. Logic is changed because of unreliable modification times on folders. Removal of directories is now decided by sorting on folder names (name is generated from current datetime format YmdHis). Cleanup is skipped, and a warning is given when a folder name is in a different format. + ## `3.7.0.beta1` (2016-11-02) https://github.com/capistrano/capistrano/compare/v3.6.1...v3.7.0.beta1 diff --git a/lib/capistrano/i18n.rb b/lib/capistrano/i18n.rb index 5b3a8be9..89b6ed53 100644 --- a/lib/capistrano/i18n.rb +++ b/lib/capistrano/i18n.rb @@ -12,6 +12,7 @@ en = { written_file: "create %{file}", question: "Please enter %{key} (%{default_value}): ", keeping_releases: "Keeping %{keep_releases} of %{releases} deployed releases on %{host}", + skip_cleanup: "Skipping cleanup of old releases on %{host}; unexpected foldername found (should be timestamp)", no_old_releases: "No old releases (keeping newest %{keep_releases}) on %{host}", linked_file_does_not_exist: "linked file %{file} does not exist on %{host}", cannot_rollback: "There are no older releases to rollback to", diff --git a/lib/capistrano/tasks/deploy.rake b/lib/capistrano/tasks/deploy.rake index 14d530bb..0d79ea26 100644 --- a/lib/capistrano/tasks/deploy.rake +++ b/lib/capistrano/tasks/deploy.rake @@ -148,8 +148,10 @@ namespace :deploy do desc "Clean up old releases" task :cleanup do on release_roles :all do |host| - releases = capture(:ls, "-xtr", releases_path).split - if releases.count >= fetch(:keep_releases) + releases = capture(:ls, "-x", releases_path).split + if !(releases.all? { |e| /^\d{14}$/ =~ e }) + warn t(:skip_cleanup, host: host.to_s) + elsif releases.count >= fetch(:keep_releases) info t(:keeping_releases, host: host.to_s, keep_releases: fetch(:keep_releases), releases: releases.count) directories = (releases - releases.last(fetch(:keep_releases))) if directories.any?