kaizendorks / pymongo_inmemory

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

Issue on init of pymongo-inmemory on Windows #45

Closed rdar-lab closed 3 years ago

rdar-lab commented 3 years ago

Describe the bug Start in windows fails on machine where pymongo-inmemory was already running in the past

To Reproduce Steps to reproduce the behavior:

  1. Create a python app with pymongo-inmemory:0.2.0. Make sure to use venv
  2. Run it, make sure that the pymongo downloads and run the mongo server
  3. Stop it
  4. Run it again
  5. You get a permission error

Expected behavior The second run works

Logs On the second run, you get a "permission denied" from line 245 in init.py of the pymongo_inmemory/downloader. The reason is that py

Context:

On the second run, you get a "permission denied" from line 245 in init.py of the pymongo_inmemory/downloader. The reason is that pymongo-inmemory attempts to delete the 'bin' folder, but there is a permission denied on the files that are there. This is because of the commands in line 88 that change the permission of the files.

Workaround: Before starting pymongo-inmemory, perform the following code: if os.path.exists("/.cache/bin"): recursive_chmod( "/.cache/bin", stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH )

def recursive_chmod(directory, mode): for root, dirs, files in os.walk(directory): for file in files: os.chmod(os.path.join(root, file), mode) for subdir in dirs: recursive_chmod(os.path.join(root, subdir), mode) os.chmod(directory, mode)

rdar-lab commented 3 years ago

Duplicate of https://github.com/kaizendorks/pymongo_inmemory/issues/41