Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Scorm file upload error #79

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 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_ALT_SEP = '\\'


@XBlock.wants("settings")
Expand Down Expand Up @@ -384,7 +385,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 @@ -943,5 +946,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