micropython/tests/extmod/vfs_posix_paths.py.exp
Christian Walther be28829ae8 extmod/vfs_posix: Fix getcwd() on non-root VFS.
The unwritten API contract expected of a VFS.getcwd() by mp_vfs_getcwd()
is that its return value should be either "" or "/" when the CWD is at
the root of the VFS and otherwise start with a slash and not end with a
slash. This was not correctly implemented in VfsPosix for instances with
a non-empty root - the required leading slash, if any, was cut off
because the root length includes a trailing slash. This would result in
missing slashes in the middle of the return value of os.getcwd() or in
uninitialized garbage from beyond a string's null terminator when the
CWD was at the VFS root.

Signed-off-by: Christian Walther <cwalther@gmx.ch>
2023-10-19 16:21:09 +02:00

24 lines
489 B
Plaintext

listdir("/"): ['subdir']
listdir("."): ['subdir']
getcwd() in {"", "/"}: True
chdir("subdir"): None
getcwd(): /subdir
mkdir("two"): None
listdir("/"): ['subdir']
listdir("/subdir"): ['file.py', 'one', 'two']
listdir("."): ['file.py', 'one', 'two']
print('hello')
hello
<module 'file' from 'file.py'>
chdir("/mnt/dir"): None
getcwd(): /mnt/dir
chdir("/mnt"): None
getcwd(): /mnt
chdir("/"): None
getcwd(): /
chdir("/mnt/dir"): None
getcwd(): /mnt/dir
chdir(".."): None
getcwd(): /mnt
False