Skip to content

Commit

Permalink
Check for 404 error response in exists()
Browse files Browse the repository at this point in the history
  • Loading branch information
deadbeef404 committed Sep 24, 2020
1 parent b9bec8b commit 8f8c4aa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,14 @@ def exists(self, name):
try:
self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name)
return True
except ClientError:
return False
except ClientError as error:
if error.response.get('Error', {}).get('Code') == '404':
return False

# Some other error was encountered. As `get_available_name` calls this,
# we have to assume the filename is unavailable. If we return true due to some
# other error, we'd overwrite a file.
return True

def listdir(self, name):
path = self._normalize_name(self._clean_name(name))
Expand Down

0 comments on commit 8f8c4aa

Please sign in to comment.