The original implementation of memory-mapped files in the Erofs class used parameters specific to POSIX-compliant systems, causing compatibility issues on Windows. This resulted in an AttributeError because mmap.MAP_SHARED and mmap.PROT_READ are not available on Windows.
Solution:
Implemented a conditional check within the Erofs class constructor to determine the operating system at runtime. Based on the OS, it now selects the appropriate parameters for the mmap.mmap() function. This update ensures that the memory mapping functionality works seamlessly across Windows, Linux, and macOS.
Changes:
Added an OS check in the Erofs.__init__ method to use mmap.MAP_SHARED and mmap.PROT_READ on POSIX-compliant systems (Linux and macOS) and mmap.ACCESS_READ on Windows.
Raised an OSError for any unsupported operating systems to prevent undefined behavior.
This update enhances the portability of the Erofs filesystem extractor tool, making it more robust and user-friendly across different development environments.
Cross-Platform Memory Mapping Compatibility
Problem:
The original implementation of memory-mapped files in the Erofs class used parameters specific to POSIX-compliant systems, causing compatibility issues on Windows. This resulted in an
AttributeError
becausemmap.MAP_SHARED
andmmap.PROT_READ
are not available on Windows.Solution:
Implemented a conditional check within the Erofs class constructor to determine the operating system at runtime. Based on the OS, it now selects the appropriate parameters for the
mmap.mmap()
function. This update ensures that the memory mapping functionality works seamlessly across Windows, Linux, and macOS.Changes:
Erofs.__init__
method to usemmap.MAP_SHARED
andmmap.PROT_READ
on POSIX-compliant systems (Linux and macOS) andmmap.ACCESS_READ
on Windows.OSError
for any unsupported operating systems to prevent undefined behavior.This update enhances the portability of the Erofs filesystem extractor tool, making it more robust and user-friendly across different development environments.