From b2ab6f840662131bcd4073f942a465d9fa0bbb30 Mon Sep 17 00:00:00 2001 From: "M. de Krijger" Date: Mon, 5 Dec 2016 12:35:18 +0100 Subject: [PATCH 1/4] Fixes Bug #1810 removal of old releases --- lib/capistrano/i18n.rb | 1 + lib/capistrano/tasks/deploy.rake | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) 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..fdedda3d 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? From d04c1e3ea33e84b183d056b71c7cacf7744ce7ad Mon Sep 17 00:00:00 2001 From: "M. de Krijger" Date: Mon, 5 Dec 2016 12:40:41 +0100 Subject: [PATCH 2/4] Corrected style issue --- lib/capistrano/tasks/deploy.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano/tasks/deploy.rake b/lib/capistrano/tasks/deploy.rake index fdedda3d..0d79ea26 100644 --- a/lib/capistrano/tasks/deploy.rake +++ b/lib/capistrano/tasks/deploy.rake @@ -149,7 +149,7 @@ namespace :deploy do task :cleanup do on release_roles :all do |host| releases = capture(:ls, "-x", releases_path).split - if !(releases.all? { |e| /^\d{14}$/ =~ e}) + 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) From 3ee9536918643fe013b50b090d4c3fd7bd192ea0 Mon Sep 17 00:00:00 2001 From: "M. de Krijger" Date: Wed, 7 Dec 2016 13:00:26 +0100 Subject: [PATCH 3/4] Added Changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa86c3a8..bb31089c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Reverse Chronological Order: 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) From 42a6ee1925f6564afd8662c1bd9806e6611ae84a Mon Sep 17 00:00:00 2001 From: "M. de Krijger" Date: Wed, 7 Dec 2016 13:05:41 +0100 Subject: [PATCH 4/4] Added your contribution here back to CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb31089c..fc2299ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ Reverse Chronological Order: 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)