49
49
from requests .exceptions import HTTPError
50
50
51
51
from internetarchive .utils import IdentifierListAsItems , get_md5 , chunk_generator , \
52
- IterableToFileAdapter , iter_directory , recursive_file_count , norm_filepath
52
+ IterableToFileAdapter , iter_directory , norm_filepath
53
53
from internetarchive .files import File
54
54
from internetarchive .iarequest import MetadataRequest , S3Request
55
55
from internetarchive .auth import S3Auth
@@ -1165,45 +1165,32 @@ def upload(self, files,
1165
1165
"""
1166
1166
queue_derive = True if queue_derive is None else queue_derive
1167
1167
remote_dir_name = None
1168
- total_files = None
1168
+
1169
1169
if isinstance (files , dict ):
1170
1170
if files .get ('name' ):
1171
1171
files = [files ]
1172
- total_files = 1
1173
1172
else :
1174
1173
files = list (files .items ())
1175
1174
if not isinstance (files , (list , tuple )):
1176
1175
files = [files ]
1177
- if all (isinstance (f , dict ) and f .get ('name' ) for f in files ):
1178
- total_files = len (files )
1179
1176
1180
1177
responses = []
1181
1178
file_index = 0
1182
- if queue_derive and total_files is None :
1183
- if checksum :
1184
- total_files = recursive_file_count (files , item = self , checksum = True )
1185
- else :
1186
- total_files = recursive_file_count (files , item = self , checksum = False )
1187
1179
file_metadata = None
1188
1180
for f in files :
1181
+
1189
1182
if isinstance (f , dict ):
1190
1183
if f .get ('name' ):
1191
1184
file_metadata = f .copy ()
1192
1185
del file_metadata ['name' ]
1193
1186
f = f ['name' ]
1187
+
1194
1188
if (isinstance (f , string_types ) and is_dir (f )) \
1195
1189
or (isinstance (f , tuple ) and is_dir (f [- 1 ])):
1196
1190
if isinstance (f , tuple ):
1197
1191
remote_dir_name = f [0 ].strip ('/' )
1198
1192
f = f [- 1 ]
1199
1193
for filepath , key in iter_directory (f ):
1200
- file_index += 1
1201
- # Set derive header if queue_derive is True,
1202
- # and this is the last request being made.
1203
- if queue_derive is True and file_index >= total_files :
1204
- _queue_derive = True
1205
- else :
1206
- _queue_derive = False
1207
1194
if not f .endswith ('/' ):
1208
1195
if remote_dir_name :
1209
1196
key = '{0}{1}/{2}' .format (remote_dir_name , f , key )
@@ -1219,7 +1206,7 @@ def upload(self, files,
1219
1206
headers = headers ,
1220
1207
access_key = access_key ,
1221
1208
secret_key = secret_key ,
1222
- queue_derive = _queue_derive ,
1209
+ queue_derive = False ,
1223
1210
verbose = verbose ,
1224
1211
verify = verify ,
1225
1212
checksum = checksum ,
@@ -1231,15 +1218,6 @@ def upload(self, files,
1231
1218
request_kwargs = request_kwargs )
1232
1219
responses .append (resp )
1233
1220
else :
1234
- file_index += 1
1235
- # Set derive header if queue_derive is True,
1236
- # and this is the last request being made.
1237
- # if queue_derive is True and file_index >= len(files):
1238
- if queue_derive is True and file_index >= total_files :
1239
- _queue_derive = True
1240
- else :
1241
- _queue_derive = False
1242
-
1243
1221
if not isinstance (f , (list , tuple )):
1244
1222
key , body = (None , f )
1245
1223
else :
@@ -1253,7 +1231,7 @@ def upload(self, files,
1253
1231
headers = headers ,
1254
1232
access_key = access_key ,
1255
1233
secret_key = secret_key ,
1256
- queue_derive = _queue_derive ,
1234
+ queue_derive = False ,
1257
1235
verbose = verbose ,
1258
1236
verify = verify ,
1259
1237
checksum = checksum ,
@@ -1264,6 +1242,12 @@ def upload(self, files,
1264
1242
validate_identifier = validate_identifier ,
1265
1243
request_kwargs = request_kwargs )
1266
1244
responses .append (resp )
1245
+
1246
+ if queue_derive :
1247
+ # Came this far without any exceptions raised, so all uploads
1248
+ # probably completed successfully. Derive now.
1249
+ self .derive ()
1250
+
1267
1251
return responses
1268
1252
1269
1253
0 commit comments