Skip to content

Commit

Permalink
Merge pull request #151 from SardineFish/main
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre authored Nov 29, 2024
2 parents 8f4baae + c296aa7 commit b27f89d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/emulation/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function resolveMount(path: string, ctx: V_Context): ResolvedMount {
const sortedMounts = [...mounts].sort((a, b) => (a[0].length > b[0].length ? -1 : 1)); // descending order of the string length
for (const [mountPoint, fs] of sortedMounts) {
// We know path is normalized, so it would be a substring of the mount point.
if (mountPoint.length <= path.length && path.startsWith(mountPoint)) {
if (_isParentOf(mountPoint, path)) {
path = path.slice(mountPoint.length > 1 ? mountPoint.length : 0); // Resolve the path relative to the mount point
if (path === '') {
path = root;
Expand Down Expand Up @@ -219,3 +219,14 @@ export function chroot<T extends V_Context>(this: T & V_Context, path: string, i
}
return bindContext(join(this?.root || '/', path), creds);
}

/**
* @internal @hidden
*/
function _isParentOf(parent: string, child: string): boolean {
if (parent === '/' || parent === child) return true;

if (!parent.endsWith('/')) parent += '/';

return child.startsWith(parent);
}

0 comments on commit b27f89d

Please sign in to comment.