@@ -69,6 +69,14 @@ def __init__(self, output_path, output_url, copy_function=None):
69
69
self .copy_function = copy_function
70
70
71
71
def _do_store (self , output ):
72
+ """Copy output to final storage location.
73
+
74
+ - Create output directory
75
+ - Check available file space
76
+ - Create output file name, taking care of possible duplicates
77
+ - Copy / link output in work directory to output directory
78
+ - Return store type, output path and output URL
79
+ """
72
80
import platform
73
81
import math
74
82
import tempfile
@@ -78,6 +86,11 @@ def _do_store(self, output):
78
86
79
87
request_uuid = output .uuid or uuid .uuid1 ()
80
88
89
+ # Create a target folder for each request
90
+ target = os .path .join (self .target , str (request_uuid ))
91
+ if not os .path .exists (target ):
92
+ os .makedirs (target )
93
+
81
94
# st.blksize is not available in windows, skips the validation on windows
82
95
if platform .system () != 'Windows' :
83
96
file_block_size = os .stat (file_name ).st_blksize
@@ -91,11 +104,6 @@ def _do_store(self, output):
91
104
if avail_size < actual_file_size :
92
105
raise NotEnoughStorage ('Not enough space in {} to store {}' .format (self .target , file_name ))
93
106
94
- # create a target folder for each request
95
- target = os .path .join (self .target , str (request_uuid ))
96
- if not os .path .exists (target ):
97
- os .makedirs (target )
98
-
99
107
# build output name
100
108
output_name , suffix = _build_output_name (output )
101
109
# build tempfile in case of duplicates
@@ -116,7 +124,7 @@ def _do_store(self, output):
116
124
url = self .url ("{}/{}" .format (request_uuid , just_file_name ))
117
125
LOGGER .info ('File output URI: {}' .format (url ))
118
126
119
- return ( STORE_TYPE .PATH , output_name , url )
127
+ return STORE_TYPE .PATH , output_name , url
120
128
121
129
@staticmethod
122
130
def copy (src , dst , copy_function = None ):
@@ -134,7 +142,7 @@ def copy(src, dst, copy_function=None):
134
142
try :
135
143
os .link (src , dst )
136
144
except Exception :
137
- LOGGER .warn ("Could not create hardlink. Fallback to copy." )
145
+ LOGGER .warning ("Could not create hardlink. Fallback to copy." )
138
146
FileStorage .copy (src , dst )
139
147
else :
140
148
shutil .copy2 (src , dst )
0 commit comments