From 33fb7dd1337744e44d281d312e4b593de74785de Mon Sep 17 00:00:00 2001 From: Nick Mitchell Date: Wed, 11 Jan 2023 19:34:05 -0500 Subject: [PATCH] fix: race condition in vfs mounting can result in ENOENT e.g. we might mount in an order that results in /kui/madwizard being overridden by /kui (both being VFS mounts) this is due to a bug in the sorting comparator --- plugins/plugin-bash-like/fs/src/vfs/index.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/plugins/plugin-bash-like/fs/src/vfs/index.ts b/plugins/plugin-bash-like/fs/src/vfs/index.ts index 4975a122a1c..4777b1b969a 100644 --- a/plugins/plugin-bash-like/fs/src/vfs/index.ts +++ b/plugins/plugin-bash-like/fs/src/vfs/index.ts @@ -126,22 +126,8 @@ const _currentMounts: VFS[] = [] function orient(A: VFS, B: VFS) { const a = A.mountPath.split(/\//).filter(_ => _) const b = B.mountPath.split(/\//).filter(_ => _) - let lastCommonIdx = 0 - const N = Math.min(a.length, b.length) - while (++lastCommonIdx < N) { - if (a[lastCommonIdx] !== b[lastCommonIdx]) { - break - } - } - - if (lastCommonIdx === 0 || a.length === b.length) { - return 0 - } else if (lastCommonIdx === a.length) { - return -1 - } else { - return b.length - a.length - } + return b.length - a.length } /** Low-level mount */