kaizendorks / pymongo_inmemory

A mongo mocking library with an ephemeral MongoDB running in memory.
MIT License
40 stars 13 forks source link

Add file permisison management for Windows platform #10

Closed ekarademir closed 3 years ago

ekarademir commented 4 years ago

During #9 I realised that Python doesn't handle chmod operations very well on Windows. It simply creates read-only files.

Although this is not a problem for executing the downloaded binary, it becomes a problem if we try to overwrite. This is not a blocking issue, because the folders are separated by their versions, and once a version is downloaded, there wouldn't be a reason to overwrite contents other than user explicitly deleting them, in which case, there is no issue.

This is more of a further goal in the future, if we need more file system tooling.

leonardoleanodev commented 3 years ago

@ekarademir I have the same problem I had to use a try except in the base code to pass the issue about permission, I could over come this with the documentation of this issue in python:

https://bugs.python.org/issue43657

my code, as soon as I can I will open an MR:

pymongo\downloader__init__.py

# line 245
try:
    shutil.rmtree(bin_dir)
except PermissionError as error:
    shutil.rmtree(bin_dir, onerror=remove_readonly)
    def remove_readonly(func, path, _):
        "Clear the readonly bit and reattempt the removal"
        os.chmod(path, stat.S_IWRITE)
        func(path)

an Warning was raised after that but I am investigating it

ekarademir commented 3 years ago

Thank you @LeonardoLeano333 I'm interested in your findings after investigation. We are not aiming Windows as a primary platform to use this library but never the less, full compatibility will be great.