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

[libcloud] switch to clean name util #1199

Merged
merged 1 commit into from
Dec 18, 2022
Merged
Changes from all commits
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
12 changes: 4 additions & 8 deletions storages/backends/apache_libcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Aymeric Barantal (mric at chamal.fr) 2011
#
import io
import os
from urllib.parse import urljoin

from django.conf import settings
Expand All @@ -11,6 +10,8 @@
from django.core.files.storage import Storage
from django.utils.deconstruct import deconstructible

from storages.utils import clean_name

try:
from libcloud.storage.providers import get_driver
from libcloud.storage.types import ObjectDoesNotExistError
Expand Down Expand Up @@ -61,15 +62,10 @@ def _get_bucket(self):
"""Helper to get bucket object (libcloud container)"""
return self.driver.get_container(self.bucket)

def _clean_name(self, name):
"""Clean name (windows directories)"""
return os.path.normpath(name).replace('\\', '/')

def _get_object(self, name):
"""Get object by its name. Return None if object not found"""
clean_name = self._clean_name(name)
try:
return self.driver.get_object(self.bucket, clean_name)
return self.driver.get_object(self.bucket, clean_name(name))
except ObjectDoesNotExistError:
return None

Expand All @@ -92,7 +88,7 @@ def listdir(self, path='/'):
"""
container = self._get_bucket()
objects = self.driver.list_container_objects(container)
path = self._clean_name(path)
path = clean_name(path)
if not path.endswith('/'):
path = "%s/" % path
files = []
Expand Down