From: Gao Xiang Date: Fri, 22 Nov 2024 07:56:59 +0000 (+0800) Subject: erofs-utils: fix `Not a directory` error for incremental builds X-Git-Tag: accepted/tizen/unified/20250610.081809~92 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c15004f5d417670aec191d07afb7c28bc69e7eb7;p=platform%2Fupstream%2Ferofs-utils.git erofs-utils: fix `Not a directory` error for incremental builds If an incremental layer contains a directory but the same path in the base layer is a non-directory, it will fail unexpectedly. Fix it now. Reported-by: Hongzhen Luo Co-developped-by: Hongzhen Luo Fixes: f64d9d02576b ("erofs-utils: introduce incremental builds") Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20241122075659.2869515-1-hsiangkao@linux.alibaba.com --- diff --git a/lib/rebuild.c b/lib/rebuild.c index 08c1b86..b37823e 100644 --- a/lib/rebuild.c +++ b/lib/rebuild.c @@ -465,7 +465,9 @@ static int erofs_rebuild_basedir_dirent_iter(struct erofs_dir_context *ctx) struct erofs_inode *inode = d->inode; /* update sub-directories only for recursively loading */ - if (S_ISDIR(inode->i_mode)) { + if (S_ISDIR(inode->i_mode) && + (ctx->de_ftype == EROFS_FT_DIR || + ctx->de_ftype == EROFS_FT_UNKNOWN)) { list_del(&inode->i_hash); inode->dev = dir->sbi->dev; inode->i_ino[1] = ctx->de_nid; @@ -497,6 +499,15 @@ int erofs_rebuild_load_basedir(struct erofs_inode *dir) if (__erofs_unlikely(IS_ROOT(dir))) dir->xattr_isize = fakeinode.xattr_isize; + /* + * May be triggered if ftype == EROFS_FT_UNKNOWN, which is impossible + * with the current mkfs. + */ + if (__erofs_unlikely(!S_ISDIR(fakeinode.i_mode))) { + DBG_BUGON(1); + return 0; + } + ctx = (struct erofs_rebuild_dir_context) { .ctx.dir = &fakeinode, .ctx.cb = erofs_rebuild_basedir_dirent_iter,