From eef629e1f4ea341535067132f70c913345eeeae4 Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Sun, 18 Dec 2022 15:06:07 -0800 Subject: [PATCH] [libcloud] switch to clean name util (#1199) --- storages/backends/apache_libcloud.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/storages/backends/apache_libcloud.py b/storages/backends/apache_libcloud.py index e9d62a58a..90862cce8 100644 --- a/storages/backends/apache_libcloud.py +++ b/storages/backends/apache_libcloud.py @@ -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 @@ -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 @@ -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 @@ -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 = []