-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
vfs.VfsPosix('.') gets confused if cwd changes #17012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Off to a roaring start, the UNIX port on macOS gives me:
Where import os
from vfs import VfsPosix as Vfs
print(os.getcwd())
v=Vfs('.')
print(v.getcwd()) Looking at the VfsPosix source: micropython/extmod/vfs_posix.c Lines 126 to 137 in 35d4d2d
It looks like
And, indeed, if I specify a path like that I get the same UnicodeError. However: import os
from vfs import VfsPosix as Vfs
print(os.getcwd())
v=Vfs('/./')
print(v.getcwd()) Produces a similar broken path bug to yours, except it's chopped off the front...
There is something going on here! Edit: under the hood this just calls the Posix Since
Specifying a root to Some more info here: #12137 A particular tidbit of that is:
So perhaps there are more bugs in VfsPosix, but also they are broadly worked around when it's used with |
Right, I saw that I think this bug just manifests when non-empty and non-absolute roots are supplied to the constructor. I did get the impression from my (non-systematic, exploratory) testing that such roots did make a difference to some operations --- for instance that they constrained when a I agree there are workarounds. But since this seemed to be buggy behavior, that could potentially lead to corrupted data or worse, I thought it should be noted and fixed. |
Port, board and/or hardware
Unix port, installed on Alpine Linux (uses musl libc)
MicroPython version
MicroPython v1.24.1 on 2025-03-14; linux [GCC 14.2.0] version
If I create a VfsPosix object rooted at '.', and query the working directory with the
getcwd()
method, I get a sane result (""
). If I then change the working directory, either by using thechdir()
method on that object, or using theos
module, and query the working directory again through the VfsPosix object, I get an invalid result (just some trailing characters from the correct result). This invalid result persists (that is, it doesn't update) even if Ichdir()
a second time.Reproduction
Expected behaviour
Expected second
v.getcwd()
call to return something like"foo"
or"./foo"
or"/foo"
. Expected thirdv.getcwd()
call to return something like""
again.Observed behaviour
Output given in Reproduction.
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
The text was updated successfully, but these errors were encountered: