Skip to content

Commit

Permalink
fix: Scorm file upload error (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
talhaaslam01 authored Jul 1, 2024
1 parent 3572f67 commit a5c8dce
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion openedxscorm/scormxblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _(text):


logger = logging.getLogger(__name__)
OS_PATH_ALT_SEP = '\\'


@XBlock.wants("settings")
Expand Down Expand Up @@ -391,7 +392,9 @@ def extract_package(self, package_file):
# the is_dir() method to verify whether a ZipInfo object points to a
# directory.
# https://docs.python.org/3.6/library/zipfile.html#zipfile.ZipInfo.is_dir
if not zipinfo.filename.endswith("/"):
# TODO: remove backported 'is_dir' method once upgraded to
# python 3.12.3 or greater.
if not is_dir(zipinfo):
dest_path = os.path.join(
self.extract_folder_path,
os.path.relpath(zipinfo.filename, root_path),
Expand Down Expand Up @@ -950,5 +953,18 @@ def parse_validate_positive_float(value, name):
return parsed


def is_dir(zipinfo):
"""Return True if this archive member is a directory."""
if zipinfo.filename.endswith('/'):
return True
elif zipinfo.filename.endswith((os.path.sep, OS_PATH_ALT_SEP)):
# The ZIP format specification requires to use forward slashes
# as the directory separator, but in practice some ZIP files
# created on Windows can use backward slashes. For compatibility
# with the extraction code which already handles this:
return True
return False


class ScormError(Exception):
pass

0 comments on commit a5c8dce

Please sign in to comment.