@@ -341,7 +341,7 @@ def popup_window(self, request, _suffix):
341
341
return Response (body = rendered )
342
342
343
343
def clean_storage (self ):
344
- if self .storage . exists (self .extract_folder_base_path ):
344
+ if self .path_exists (self .extract_folder_base_path ):
345
345
logger .info (
346
346
'Removing previously unzipped "%s"' , self .extract_folder_base_path
347
347
)
@@ -400,7 +400,7 @@ def index_page_url(self):
400
400
return ""
401
401
folder = self .extract_folder_path
402
402
if self .storage .exists (
403
- os .path .join (self .extract_folder_base_path , self .index_page_path )
403
+ os .path .join (self .extract_folder_base_path , self .clean_path ( self . index_page_path ) )
404
404
):
405
405
# For backward-compatibility, we must handle the case when the xblock data
406
406
# is stored in the base folder.
@@ -417,14 +417,30 @@ def extract_folder_path(self):
417
417
"""
418
418
return os .path .join (self .extract_folder_base_path , self .package_meta ["sha1" ])
419
419
420
+ def clean_path (self , path ):
421
+ """
422
+ Removes query string from a path
423
+ """
424
+ return path .split ('?' )[0 ] if path else path
425
+
426
+ def path_exists (self , path ):
427
+ """
428
+ Returs True if given path exists in storage otherwise returns False
429
+ """
430
+ try :
431
+ dirs , files = self .storage .listdir (path )
432
+ return True if dirs or files else False
433
+ except FileNotFoundError :
434
+ return False
435
+
420
436
@property
421
437
def extract_folder_base_path (self ):
422
438
"""
423
439
Path to the folder where packages will be extracted.
424
440
Compute hash of the unique block usage_id and use that as our directory name.
425
441
"""
426
442
# For backwards compatibility, we return the old path if the directory exists
427
- if self .storage . exists (self .extract_old_folder_base_path ):
443
+ if self .path_exists (self .extract_old_folder_base_path ):
428
444
return self .extract_old_folder_base_path
429
445
sha1 = hashlib .sha1 ()
430
446
sha1 .update (str (self .scope_ids .usage_id ).encode ())
0 commit comments