From 8c054ed71d579aef53e074fcdaea56f110f1764e Mon Sep 17 00:00:00 2001 From: François Freitag Date: Fri, 26 Aug 2016 17:54:06 -0700 Subject: Fixed #27108 -- Displayed collectstatic's delete/overwrite warnings only if some files exist in STATIC_ROOT. --- .../management/commands/collectstatic.py | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'django') diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py index db29ff73cc..ef3bb67d7e 100644 --- a/django/contrib/staticfiles/management/commands/collectstatic.py +++ b/django/contrib/staticfiles/management/commands/collectstatic.py @@ -173,22 +173,28 @@ class Command(BaseCommand): if self.is_local_storage() and self.storage.location: destination_path = self.storage.location message.append(':\n\n %s\n\n' % destination_path) + should_warn_user = ( + self.storage.exists(destination_path) and + any(self.storage.listdir(destination_path)) + ) else: destination_path = None message.append('.\n\n') + # Destination files existence not checked; play it safe and warn. + should_warn_user = True - if self.clear: - message.append('This will DELETE ALL FILES in this location!\n') - else: - message.append('This will overwrite existing files!\n') - - message.append( - 'Are you sure you want to do this?\n\n' - "Type 'yes' to continue, or 'no' to cancel: " - ) + if self.interactive and should_warn_user: + if self.clear: + message.append('This will DELETE ALL FILES in this location!\n') + else: + message.append('This will overwrite existing files!\n') - if self.interactive and input(''.join(message)) != 'yes': - raise CommandError("Collecting static files cancelled.") + message.append( + 'Are you sure you want to do this?\n\n' + "Type 'yes' to continue, or 'no' to cancel: " + ) + if input(''.join(message)) != 'yes': + raise CommandError("Collecting static files cancelled.") collected = self.collect() modified_count = len(collected['modified']) -- cgit v1.3