extmod/vfs_posix: Fix relative root path.

A VfsPosix created with a relative root path would get confused when
chdir() was called on it and become unable to properly resolve absolute
paths, because changing directories effectively shifted its root. The
simplest fix for that would be to say "don't do that", but since the
unit tests themselves do it, fix it by making a relative path absolute
before storing it.

Signed-off-by: Christian Walther <cwalther@gmx.ch>
This commit is contained in:
Christian Walther
2023-07-31 18:25:26 +02:00
parent 86c7b957a8
commit e3ba6f952b
3 changed files with 39 additions and 1 deletions

View File

@@ -99,6 +99,19 @@ if hasattr(vfs, "statvfs"):
print(type(list(vfs.ilistdir("."))[0][0]))
print(type(list(vfs.ilistdir(b"."))[0][0]))
# chdir should not affect absolute paths (regression test)
vfs.mkdir("/subdir")
vfs.mkdir("/subdir/micropy_test_dir")
with vfs.open("/subdir/micropy_test_dir/test2", "w") as f:
f.write("wrong")
vfs.chdir("/subdir")
with vfs.open("/test2", "r") as f:
print(f.read())
os.chdir(curdir)
vfs.remove("/subdir/micropy_test_dir/test2")
vfs.rmdir("/subdir/micropy_test_dir")
vfs.rmdir("/subdir")
# remove
os.remove(temp_dir + "/test2")
print(os.listdir(temp_dir))

View File

@@ -10,6 +10,7 @@ next_file_no <= base_file_no True
<class 'tuple'>
<class 'str'>
<class 'bytes'>
hello
[]
remove OSError
False