From eedd2abba0d8c3ca69a2c3023e974dd6ed3264ba Mon Sep 17 00:00:00 2001 From: Pez Cuckow Date: Tue, 27 Apr 2021 13:33:04 +0200 Subject: [PATCH] Keep backups, even when they're old. (#2734) (#2912) Recently, we encountered an issue with webpacker removing our previous assets during the webpacker:clean task, and not keeping the specified number of backups. We expected the [behavior from sprockets][sprockets], in which assets are kept if under age or within the count limit. However, webpacker only keeps assets if under age *AND* within the count limit. I think this should work like sprockets and has perhaps been overlooked. [sprockets]: https://github.com/rails/sprockets/blob/358f83ff09a77f69ac17543a9b1d127737060f00/lib/sprockets/manifest.rb#L258-L259 Backport-PR-URL: https://github.com/rails/webpacker/pull/2912 Co-authored-by: Brad Dunbar --- lib/webpacker/commands.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webpacker/commands.rb b/lib/webpacker/commands.rb index e7a97b15b..d384218be 100644 --- a/lib/webpacker/commands.rb +++ b/lib/webpacker/commands.rb @@ -23,7 +23,7 @@ def clean(count = 2, age = 3600) .each_with_index .drop_while do |(mtime, _), index| max_age = [0, Time.now - Time.at(mtime)].max - max_age < age && index < count + max_age < age || index < count end .each do |(_, files), index| files.each do |file|