diff --git a/changelog.d/20240423_122156_danyal.faheem_fix_course_import_duplicate_path.md b/changelog.d/20240423_122156_danyal.faheem_fix_course_import_duplicate_path.md new file mode 100644 index 0000000..3f97391 --- /dev/null +++ b/changelog.d/20240423_122156_danyal.faheem_fix_course_import_duplicate_path.md @@ -0,0 +1,3 @@ +- [Bugfix] Prevent overwriting of exported course scorm data by imported course. (by @Danyal-Faheem) + - Use usage_key instead of block_id as the location identifier for scorm data as it is unique across course imports. + - This change will not take effect for previously created scorm modules. \ No newline at end of file diff --git a/openedxscorm/scormxblock.py b/openedxscorm/scormxblock.py index b7af42f..5395d92 100644 --- a/openedxscorm/scormxblock.py +++ b/openedxscorm/scormxblock.py @@ -411,6 +411,23 @@ def extract_folder_path(self): def extract_folder_base_path(self): """ Path to the folder where packages will be extracted. + Compute hash of the unique block usage_id and use that as our directory name. + """ + # For backwards compatibility, we return the old path if the directory exists + if self.storage.exists(self.extract_old_folder_base_path): + return self.extract_old_folder_base_path + sha1 = hashlib.sha1() + sha1.update(str(self.scope_ids.usage_id).encode()) + hashed_usage_id = sha1.hexdigest() + return os.path.join(self.scorm_location(), hashed_usage_id) + + @property + def extract_old_folder_base_path(self): + """ + Deprecated Path to the folder where packages will be extracted. + Deprecated as the block_id was shared by courses when exporting and importing + them, thus causing storage conflicts. + Only keeping this here for backwards compatibility. """ return os.path.join(self.scorm_location(), self.location.block_id)