diff options
author | Damien George <damien.p.george@gmail.com> | 2020-05-28 12:50:44 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-05-29 23:05:01 +1000 |
commit | 22806ed5df27c10131af0cedb2f7e8b134fe6e7a (patch) | |
tree | 0780301c7b5ac2efb2a6759956fc575f23a62230 /tests/extmod/vfs_basic.py | |
parent | 8f642677f724e725813155f74e5934b8c94fc1c4 (diff) |
extmod/vfs: Retain previous working directory if chdir fails.
Fixes issue #6069.
Diffstat (limited to 'tests/extmod/vfs_basic.py')
-rw-r--r-- | tests/extmod/vfs_basic.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index c8e203b3d..62b2a2773 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -10,8 +10,9 @@ except (ImportError, AttributeError): class Filesystem: - def __init__(self, id): + def __init__(self, id, fail=0): self.id = id + self.fail = fail def mount(self, readonly, mkfs): print(self.id, "mount", readonly, mkfs) @@ -25,6 +26,8 @@ class Filesystem: def chdir(self, dir): print(self.id, "chdir", dir) + if self.fail: + raise OSError(self.fail) def getcwd(self): print(self.id, "getcwd") @@ -158,3 +161,18 @@ uos.chdir("/") uos.umount("/") print(uos.listdir("/")) uos.umount("/mnt") + +# chdir to a non-existent mount point (current directory should remain unchanged) +try: + uos.chdir("/foo") +except OSError: + print("OSError") +print(uos.getcwd()) + +# chdir to a non-existent subdirectory in a mounted filesystem +uos.mount(Filesystem(5, 1), "/mnt") +try: + uos.chdir("/mnt/subdir") +except OSError: + print("OSError") +print(uos.getcwd()) |