Skip to content

Commit

Permalink
[libcloud] switch to clean name util (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschneier authored Dec 18, 2022
1 parent ed63bd8 commit eef629e
Showing 1 changed file with 4 additions and 8 deletions.
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

0 comments on commit eef629e

Please sign in to comment.