Skip to contentSkip to conversation

erofs-utils: fix `Not a directory` error for incremental builds

PATCH New Gao Xiang 1 participant 1 message Nov 22, 2024 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 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.

Fixes f64d9d02576b ("erofs-utils: introduce incremental builds")
---
 lib/rebuild.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
lib/rebuild.c +12 -1
index 08c1b86..b37823e 100644
@@ -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,
Signature · 1 line
2.43.5