diff --git a/rhodecode/apps/file_store/local_store.py b/rhodecode/apps/file_store/local_store.py --- a/rhodecode/apps/file_store/local_store.py +++ b/rhodecode/apps/file_store/local_store.py @@ -38,19 +38,18 @@ class LocalFileStorage(object): """ Resolves a unique name and the correct path. If a filename for that path already exists then a numeric prefix with values > 0 will be - added, for example test.jpg -> test-1.jpg etc. initially file would have 0 prefix. + added, for example test.jpg -> 1-test.jpg etc. initially file would have 0 prefix. :param name: base name of file :param directory: absolute directory path """ - basename, ext = os.path.splitext(name) counter = 0 while True: - name = '%s-%d%s' % (basename, counter, ext) + name = '%d-%s' % (counter, name) # sub_store prefix to optimize disk usage, e.g some_path/ab/final_file - sub_store = cls._sub_store_from_filename(basename) + sub_store = cls._sub_store_from_filename(name) sub_store_path = os.path.join(directory, sub_store) if not os.path.exists(sub_store_path): os.makedirs(sub_store_path) diff --git a/rhodecode/apps/file_store/utils.py b/rhodecode/apps/file_store/utils.py --- a/rhodecode/apps/file_store/utils.py +++ b/rhodecode/apps/file_store/utils.py @@ -19,9 +19,10 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ -import os import uuid +import pathlib2 + def get_file_storage(settings): from rhodecode.apps.file_store.local_store import LocalFileStorage @@ -30,6 +31,11 @@ def get_file_storage(settings): return LocalFileStorage(base_path=store_path) +def splitext(filename): + ext = ''.join(pathlib2.Path(filename).suffixes) + return filename, ext + + def uid_filename(filename, randomized=True): """ Generates a randomized or stable (uuid) filename, @@ -38,7 +44,8 @@ def uid_filename(filename, randomized=Tr :param filename: the original filename :param randomized: define if filename should be stable (sha1 based) or randomized """ - _, ext = os.path.splitext(filename) + + _, ext = splitext(filename) if randomized: uid = uuid.uuid4() else: