Skip to content

Commit

Permalink
fix: Scorm file upload error
Browse files Browse the repository at this point in the history
  • Loading branch information
talhaaslam01 committed Jun 28, 2024
1 parent 96fff13 commit bca5fe8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion openedxscorm/scormxblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def _(text):


logger = logging.getLogger(__name__)
os.path.altsep = '\\'


@XBlock.wants("settings")
Expand Down Expand Up @@ -384,7 +385,8 @@ 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 @@ -943,5 +945,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
# 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:
if os.path.altsep:
return zipinfo.filename.endswith((os.path.sep, os.path.altsep))
return False


class ScormError(Exception):
pass

0 comments on commit bca5fe8

Please sign in to comment.