Skip to content

vfs.VfsPosix('.') gets confused if cwd changes #17012

@dubiousjim

Description

@dubiousjim

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 the chdir() method on that object, or using the os 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 I chdir() a second time.

Reproduction

main0:~/micropython-work/test$ tree
.
└── foo

1 directories, 0 files

$ micropython
>>> import os,vfs; Vfs=vfs.VfsPosix
>>> os.getcwd()
'/home/bob/micropython-work/test'
>>> v=Vfs('.')
>>> v.getcwd()
''
>>> os.chdir('foo')
>>> os.getcwd() # output as expected
'/home/bob/micropython-work/test/foo'
>>> v.getcwd() # weird output
'oo'
>>> os.chdir('..')
>>> os.getcwd() # output as expected
'/home/bob/micropython-work/test'
>>> v.getcwd() # weird output persists
'oo'

Expected behaviour

Expected second v.getcwd() call to return something like "foo" or "./foo" or "/foo". Expected third v.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions