Skip to content

Commit

Permalink
support slash-ended mkdir, such as "mkdir dir/".
Browse files Browse the repository at this point in the history
Signed-off-by: 田昕 <tianxin7@xiaomi.com>
  • Loading branch information
XinStellaris committed May 16, 2022
1 parent 40dba4a commit 3f82e2f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,8 @@ static lfs_stag_t lfs_dir_find(lfs_t *lfs, lfs_mdir_t *dir,
LFS_MKTAG(0x780, 0, 0),
LFS_MKTAG(LFS_TYPE_NAME, 0, namelen),
// are we last name?
(strchr(name, '/') == NULL) ? id : NULL,
(((strchr(name, '/') != NULL) && (strcspn(name, "/") == strlen(name) - 1)) ||
(strchr(name, '/') == NULL)) ? id : NULL,
lfs_dir_find_match, &(struct lfs_dir_find_match){
lfs, name, namelen});
if (tag < 0) {
Expand Down Expand Up @@ -2408,7 +2409,8 @@ static int lfs_rawmkdir(lfs_t *lfs, const char *path) {
}

// check that name fits
lfs_size_t nlen = strlen(path);
// if name ends with slash, ignore it
lfs_size_t nlen = (strlen(path) > 0 && path[strlen(path) - 1] == '/') ? strlen(path) - 1 : strlen(path);
if (nlen > lfs->name_max) {
return LFS_ERR_NAMETOOLONG;
}
Expand Down

0 comments on commit 3f82e2f

Please sign in to comment.