##// END OF EJS Templates
file-store: use pathlib2 to determine complex filenames with double extensions, e.g exmaple.tar.gz
marcink -
r3728:20990e78 new-ui
parent child Browse files
Show More
@@ -38,19 +38,18 b' class LocalFileStorage(object):'
38 """
38 """
39 Resolves a unique name and the correct path. If a filename
39 Resolves a unique name and the correct path. If a filename
40 for that path already exists then a numeric prefix with values > 0 will be
40 for that path already exists then a numeric prefix with values > 0 will be
41 added, for example test.jpg -> test-1.jpg etc. initially file would have 0 prefix.
41 added, for example test.jpg -> 1-test.jpg etc. initially file would have 0 prefix.
42
42
43 :param name: base name of file
43 :param name: base name of file
44 :param directory: absolute directory path
44 :param directory: absolute directory path
45 """
45 """
46
46
47 basename, ext = os.path.splitext(name)
48 counter = 0
47 counter = 0
49 while True:
48 while True:
50 name = '%s-%d%s' % (basename, counter, ext)
49 name = '%d-%s' % (counter, name)
51
50
52 # sub_store prefix to optimize disk usage, e.g some_path/ab/final_file
51 # sub_store prefix to optimize disk usage, e.g some_path/ab/final_file
53 sub_store = cls._sub_store_from_filename(basename)
52 sub_store = cls._sub_store_from_filename(name)
54 sub_store_path = os.path.join(directory, sub_store)
53 sub_store_path = os.path.join(directory, sub_store)
55 if not os.path.exists(sub_store_path):
54 if not os.path.exists(sub_store_path):
56 os.makedirs(sub_store_path)
55 os.makedirs(sub_store_path)
@@ -19,9 +19,10 b''
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21
21
22 import os
23 import uuid
22 import uuid
24
23
24 import pathlib2
25
25
26
26 def get_file_storage(settings):
27 def get_file_storage(settings):
27 from rhodecode.apps.file_store.local_store import LocalFileStorage
28 from rhodecode.apps.file_store.local_store import LocalFileStorage
@@ -30,6 +31,11 b' def get_file_storage(settings):'
30 return LocalFileStorage(base_path=store_path)
31 return LocalFileStorage(base_path=store_path)
31
32
32
33
34 def splitext(filename):
35 ext = ''.join(pathlib2.Path(filename).suffixes)
36 return filename, ext
37
38
33 def uid_filename(filename, randomized=True):
39 def uid_filename(filename, randomized=True):
34 """
40 """
35 Generates a randomized or stable (uuid) filename,
41 Generates a randomized or stable (uuid) filename,
@@ -38,7 +44,8 b' def uid_filename(filename, randomized=Tr'
38 :param filename: the original filename
44 :param filename: the original filename
39 :param randomized: define if filename should be stable (sha1 based) or randomized
45 :param randomized: define if filename should be stable (sha1 based) or randomized
40 """
46 """
41 _, ext = os.path.splitext(filename)
47
48 _, ext = splitext(filename)
42 if randomized:
49 if randomized:
43 uid = uuid.uuid4()
50 uid = uuid.uuid4()
44 else:
51 else:
General Comments 0
You need to be logged in to leave comments. Login now