Change handling of spec deletion

Though it's not the case with `FileSystemStorage`, attempting to delete
a nonexistent file can cause an exception (as in #80). We want to avoid
these errors but don't want to suppress others raised in the process of
deleting the file, so we first check to see if the file exists.
This commit is contained in:
Matthew Tretter 2011-12-07 00:52:06 -05:00
parent 081a0a0d0f
commit dd28557323

View file

@ -238,10 +238,11 @@ class ImageSpecFile(_ImageSpecFileMixin, ImageFieldFile):
self.close()
del self.file
try:
self.storage.delete(self.name)
except (NotImplementedError, IOError):
pass
if self.name and self.storage.exists(self.name):
try:
self.storage.delete(self.name)
except NotImplementedError:
pass
# Delete the filesize cache.
if hasattr(self, '_size'):