Enforced stat/dir_read of a dir results in size=0
The size field in lfs_info doesn't really make sense for stat/dir_read when the file is a directory. Still, we should probably set it to 0 os it's not uninitialized. Fortunately we were already setting size=0 in _most_ cases, this commit is mostly just checking for size=0 in more test cases.
This commit is contained in:
@@ -8813,6 +8813,7 @@ int lfsr_stat(lfs_t *lfs, const char *path, struct lfs_info *info) {
|
||||
if (err == LFS_ERR_INVAL) {
|
||||
strcpy(info->name, "/");
|
||||
info->type = LFS_TYPE_DIR;
|
||||
info->size = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8901,13 +8902,15 @@ int lfsr_dir_read(lfs_t *lfs, lfsr_dir_t *dir, struct lfs_info *info) {
|
||||
|
||||
// handle dots specially
|
||||
if (dir->pos == 0) {
|
||||
info->type = LFS_TYPE_DIR;
|
||||
strcpy(info->name, ".");
|
||||
info->type = LFS_TYPE_DIR;
|
||||
info->size = 0;
|
||||
dir->pos += 1;
|
||||
return 0;
|
||||
} else if (dir->pos == 1) {
|
||||
info->type = LFS_TYPE_DIR;
|
||||
strcpy(info->name, "..");
|
||||
info->type = LFS_TYPE_DIR;
|
||||
info->size = 0;
|
||||
dir->pos += 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user