diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py index 246f960583c57..341537ffa728b 100644 --- a/django/contrib/staticfiles/management/commands/collectstatic.py +++ b/django/contrib/staticfiles/management/commands/collectstatic.py @@ -1,3 +1,5 @@ +from __future__ import with_statement + import os import sys from optparse import make_option @@ -9,6 +11,7 @@ from django.contrib.staticfiles import finders + class Command(NoArgsCommand): """ Command that allows to copy or symlink media files from different @@ -236,7 +239,7 @@ def copy_file(self, path, prefixed_path, source_storage): os.makedirs(os.path.dirname(full_path)) except OSError: pass - source_file = source_storage.open(path) - self.storage.save(prefixed_path, source_file) + with source_storage.open(path) as source_file: + self.storage.save(prefixed_path, source_file) if not prefixed_path in self.copied_files: self.copied_files.append(prefixed_path)