Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the problem that arises when using --clear in python manage.py collectstatic #1403

Merged
merged 3 commits into from
May 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions storages/backends/azure_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ def get_available_name(self, name, max_length=_AZURE_NAME_MAX_LEN):
return super().get_available_name(name, max_length)

def exists(self, name):
if not name:
try:
self.service_client.get_container_client(
self.azure_container
)
Frodothedwarf marked this conversation as resolved.
Show resolved Hide resolved
return True
except:
return False

blob_client = self.client.get_blob_client(self._get_valid_path(name))
return blob_client.exists()

Expand Down Expand Up @@ -390,16 +399,9 @@ def list_all(self, path=""):

def listdir(self, path=""):
"""
Return directories and files for a given path.
Leave the path empty to list the root.
Order of dirs and files is undefined.
Return all files for a given path.
Given that Azure can't return paths it only returns files.
Works great for our little adventure.
"""
files = []
dirs = set()
for name in self.list_all(path):
n = name[len(path) :]
if "/" in n:
dirs.add(n.split("/", 1)[0])
else:
files.append(n)
return list(dirs), files

return [], self.list_all(path)
Frodothedwarf marked this conversation as resolved.
Show resolved Hide resolved