kaizendorks / pymongo_inmemory

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

Windows Store Python: During extraction: FileNotFoundError: [Errno 2] No such file or directory: #52

Closed SDMI-Developers closed 2 years ago

SDMI-Developers commented 2 years ago

Describe the bug This bug appears to be happening when the file directory is greater then 260 characters as limited by windows.

I played around with the downloader and tried to append this prefix to any of the paths I saw and got a little further, but no matter what I did popen couldn't find the directory.

To Reproduce Steps to reproduce the behavior:

  1. Use python from the windows app store as this stores python in a nested AppData/Local folder that makes it easy to go over the limit of 260 characters for file path.
  2. See error:
    Traceback (most recent call last):
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\parsedan\__main__.py", line 201, in <module>
    cli()
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 1053, in main
    rv = self.invoke(ctx)
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 754, in invoke
    return __callback(*args, **kwargs)
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\parsedan\__main__.py", line 115, in start
    with MongoClient() as client:
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo_inmemory\_pim.py", line 8, in __init__
    self._mongod = Mongod()
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo_inmemory\mongod.py", line 73, in __init__
    self._bin_folder = download()
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo_inmemory\downloader\__init__.py", line 218, in download
    _extract(archive_file)
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo_inmemory\downloader\__init__.py", line 110, in _extract
    _extract_zip(archive_file, extract_folder)
    File "C:\Users\jdolbe1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo_inmemory\downloader\__init__.py", line 130, in _extract_zip
    z.extract(f, extract_folder)
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\zipfile.py", line 1616, in extract
    return self._extract_member(member, path, pwd)
    File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\zipfile.py", line 1687, in _extract_member
    open(targetpath, "wb") as target:
    FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\jdolbe1\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\pymongo_inmemory\\.cache\\extract\\mongodb-windows-x86_64-4.4.6-zip\\mongodb-win32-x86_64-windows-4.4.6\\LICENSE-Community.txt'

Expected behavior The downloader to successfully extract files with path lengths greater then 260.

Context:

ekarademir commented 2 years ago

Ah, Python and its struggle with paths...

Thanks for reporting the issue. I'll work on it together with #43 . I moved houses and I am still settling in. I don't have my Windows setup properly set up yet. So this will take a bit more time to receive TLC. However if you have figured a way please feel free to create a PR.

SDMI-Developers commented 2 years ago

Ah, Python and its struggle with paths...

Thanks for reporting the issue. I'll work on it together with #43 . I moved houses and I am still settling in. I don't have my Windows setup properly set up yet. So this will take a bit more time to receive TLC. However if you have figured a way please feel free to create a PR.

Hmm im thinking one of the easiest solutions is to rename the extracted file to maybe just be the version of mongo. Right now its nested mongodb-windows-x86_64-4.4.6-zip and then again into that folder mongodb-win32-x86_64-windows-4.4.6.

Ill look into it later today!

d0lb33 commented 2 years ago

@ekarademir Are you opposed to switching the download/extracted folder to the home directory?

ekarademir commented 2 years ago

@SDMI-Developers would you be able to test if @d0lb33 's fix, which is merged to master solves your issue? I will need to add a version update before releasing the next version (I won't hold it too long, it should be done by the end of the week,) but you should be able checkout master branch and test.

d0lb33 commented 2 years ago

@SDMI-Developers would you be able to test if @d0lb33 's fix, which is merged to master solves your issue? I will need to add a version update before releasing the next version (I won't hold it too long, it should be done by the end of the week,) but you should be able checkout master branch and test.

Sorry, that is also me. haha

ekarademir commented 2 years ago

<insert spiderman meme>