Skip to content

Commit a5ea4b9

Browse files
robert-hhdpgeorge
authored andcommitted
extmod/vfs_lfsx: Fix path handling in uos.stat() to consider cur dir.
This fixes the bug, that stat(filename) would not consider the current working directory. So if e.g. the cwd is "lib", then stat("main.py") would return the info for "/main.py" instead of "/lib/main.py".
1 parent 037c83b commit a5ea4b9

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

extmod/vfs_lfsx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(MP_VFS_LFSx(getcwd_obj), MP_VFS_LFSx(getcwd));
304304

305305
STATIC mp_obj_t MP_VFS_LFSx(stat)(mp_obj_t self_in, mp_obj_t path_in) {
306306
MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in);
307-
const char *path = mp_obj_str_get_str(path_in);
307+
const char *path = MP_VFS_LFSx(make_path)(self, path_in);
308308
struct LFSx_API (info) info;
309309
int ret = LFSx_API(stat)(&self->lfs, path, &info);
310310
if (ret < 0) {

tests/extmod/vfs_lfs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ def test(bdev, vfs_class):
101101
print(vfs.getcwd())
102102
vfs.chdir("/testdir")
103103
print(vfs.getcwd())
104+
105+
# create file in directory to make sure paths are relative
106+
vfs.open("test2", "w").close()
107+
print(vfs.stat("test2"))
108+
print(vfs.stat("/testdir/test2"))
109+
vfs.remove("test2")
110+
111+
# chdir back to root and remove testdir
104112
vfs.chdir("/")
105113
print(vfs.getcwd())
106114
vfs.rmdir("testdir")

tests/extmod/vfs_lfs.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ write 3
2020
[('test', 32768, 0, 8), ('testdir', 16384, 0, 0)]
2121
/
2222
/testdir
23+
(32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
24+
(32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
2325
/
2426
test <class 'VfsLfs2'>
2527
(1024, 1024, 30, 28, 28, 0, 0, 0, 0, 255)
@@ -43,4 +45,6 @@ write 3
4345
[('testdir', 16384, 0, 0), ('test', 32768, 0, 8)]
4446
/
4547
/testdir
48+
(32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
49+
(32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
4650
/

0 commit comments

Comments
 (0)