mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 11:40:18 +01:00
extmod/vfs: Retain previous working directory if chdir fails.
Fixes issue #6069.
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -58,3 +58,9 @@ OSError
|
||||
3 umount
|
||||
['mnt']
|
||||
4 umount
|
||||
OSError
|
||||
/
|
||||
5 mount False False
|
||||
5 chdir /subdir
|
||||
OSError
|
||||
/
|
||||
|
||||
Reference in New Issue
Block a user