Skip to content

Commit 6c27e71

Browse files
fs_driver.py: fix _fs_dir_open_cb for VfsFat
While testing with an SD card that has a FAT filesystem on it, I noticed that, unlike LittleFS, VfsFat returns an [Errno 22] EINVAL when a directory has a trailing slash. This fix removes the trailing slash, except for the root directory.
1 parent 75f596c commit 6c27e71

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

api_drivers/py_api_drivers/fs_driver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ def _fs_dir_open_cb(drv, path):
7878
#print(f"_fs_dir_open_cb for path '{path}'")
7979
try:
8080
import os # for ilistdir()
81+
if path != "/":
82+
path = path.rstrip('/') # LittleFS handles trailing flashes fine, but vfs.VfsFat returns an [Errno 22] EINVAL
8183
return {'iterator' : os.ilistdir(path)}
8284
except Exception as e:
83-
print(f"_fs_dir_open_cb exception: {e}")
85+
print(f"_fs_dir_open_cb exception for path {path}: {e}")
8486
return None
8587

8688
def _fs_dir_read_cb(drv, lv_fs_dir_t, buf, btr):

0 commit comments

Comments
 (0)