extmod/vfs_lfsx: Normalize path name in chdir.

This change scans for '.', '..' and multiple '/' and normalizes the new
path name.  If the resulting path does not exist, an error is raised.
Non-existing interim path elements are ignored if they are removed during
normalization.
This commit is contained in:
robert
2020-05-03 21:05:08 +02:00
committed by Damien George
parent a5ea4b9f3f
commit d3ea28d04a
3 changed files with 81 additions and 0 deletions

View File

@@ -98,6 +98,8 @@ def test(bdev, vfs_class):
print(list(vfs.ilistdir()))
# getcwd, chdir
vfs.mkdir("/testdir2")
vfs.mkdir("/testdir/subdir")
print(vfs.getcwd())
vfs.chdir("/testdir")
print(vfs.getcwd())
@@ -111,7 +113,29 @@ def test(bdev, vfs_class):
# chdir back to root and remove testdir
vfs.chdir("/")
print(vfs.getcwd())
vfs.chdir("testdir")
print(vfs.getcwd())
vfs.chdir("..")
print(vfs.getcwd())
vfs.chdir("testdir/subdir")
print(vfs.getcwd())
vfs.chdir("../..")
print(vfs.getcwd())
vfs.chdir("/./testdir2")
print(vfs.getcwd())
vfs.chdir("../testdir")
print(vfs.getcwd())
vfs.chdir("../..")
print(vfs.getcwd())
vfs.chdir(".//testdir")
print(vfs.getcwd())
vfs.chdir("subdir/./")
print(vfs.getcwd())
vfs.chdir("/")
print(vfs.getcwd())
vfs.rmdir("testdir/subdir")
vfs.rmdir("testdir")
vfs.rmdir("testdir2")
bdev = RAMBlockDevice(30)

View File

@@ -23,6 +23,16 @@ write 3
(32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
(32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
/
/testdir
/
/testdir/subdir
/
/testdir2
/testdir
/
/testdir
/testdir/subdir
/
test <class 'VfsLfs2'>
(1024, 1024, 30, 28, 28, 0, 0, 0, 0, 255)
(1024, 1024, 30, 28, 28, 0, 0, 0, 0, 255)
@@ -48,3 +58,13 @@ write 3
(32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
(32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
/
/testdir
/
/testdir/subdir
/
/testdir2
/testdir
/
/testdir
/testdir/subdir
/