summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-05-14 21:37:59 +1000
committerDamien George <damien.p.george@gmail.com>2020-05-15 11:31:32 +1000
commit7dffbfd22a128d88cd4cd7f23ebf24c46ae8791f (patch)
treea975ad37bd465e94146fe6a1cc03eaf18081a9e2
parent463c0fb2f4fa5dfd79598c4d8681a007704c2ee1 (diff)
downloadmicropython-7dffbfd22a128d88cd4cd7f23ebf24c46ae8791f.tar.gz
micropython-7dffbfd22a128d88cd4cd7f23ebf24c46ae8791f.zip
extmod/vfs_lfsx: Fix import_stat so it takes into account current dir.
CPython semantics require searching the current directory if the import is not absolute (when "" is in sys.path). Fixes issue #6037.
-rw-r--r--extmod/vfs_lfsx.c3
-rw-r--r--tests/extmod/vfs_lfs_mount.py7
-rw-r--r--tests/extmod/vfs_lfs_mount.py.exp2
3 files changed, 12 insertions, 0 deletions
diff --git a/extmod/vfs_lfsx.c b/extmod/vfs_lfsx.c
index 843e706da4..c624096782 100644
--- a/extmod/vfs_lfsx.c
+++ b/extmod/vfs_lfsx.c
@@ -31,6 +31,7 @@
#include "py/stream.h"
#include "py/binary.h"
#include "py/objarray.h"
+#include "py/objstr.h"
#include "py/mperrno.h"
#include "extmod/vfs.h"
@@ -440,6 +441,8 @@ STATIC MP_DEFINE_CONST_DICT(MP_VFS_LFSx(locals_dict), MP_VFS_LFSx(locals_dict_ta
STATIC mp_import_stat_t MP_VFS_LFSx(import_stat)(void *self_in, const char *path) {
MP_OBJ_VFS_LFSx *self = self_in;
struct LFSx_API (info) info;
+ mp_obj_str_t path_obj = { { &mp_type_str }, 0, 0, (const byte *)path };
+ path = MP_VFS_LFSx(make_path)(self, &path_obj);
int ret = LFSx_API(stat)(&self->lfs, path, &info);
if (ret == 0) {
if (info.type == LFSx_MACRO(_TYPE_REG)) {
diff --git a/tests/extmod/vfs_lfs_mount.py b/tests/extmod/vfs_lfs_mount.py
index 7ac19184b9..9207f4a8c6 100644
--- a/tests/extmod/vfs_lfs_mount.py
+++ b/tests/extmod/vfs_lfs_mount.py
@@ -58,6 +58,12 @@ def test(bdev, vfs_class):
f.write('print("package")\n')
import lfspkg
+ # chdir and import module from current directory (needs "" in sys.path)
+ uos.mkdir("/lfs/subdir")
+ uos.chdir("/lfs/subdir")
+ uos.rename("/lfs/lfsmod.py", "/lfs/subdir/lfsmod2.py")
+ import lfsmod2
+
# umount
uos.umount("/lfs")
@@ -72,6 +78,7 @@ import sys
sys.path.clear()
sys.path.append("/lfs")
+sys.path.append("")
# run tests
test(bdev, uos.VfsLfs1)
diff --git a/tests/extmod/vfs_lfs_mount.py.exp b/tests/extmod/vfs_lfs_mount.py.exp
index 90aff35016..b5c5215314 100644
--- a/tests/extmod/vfs_lfs_mount.py.exp
+++ b/tests/extmod/vfs_lfs_mount.py.exp
@@ -1,6 +1,8 @@
test <class 'VfsLfs1'>
hello from lfs
package
+hello from lfs
test <class 'VfsLfs2'>
hello from lfs
package
+hello from lfs