Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a createFolderMount util #6163

Open
wants to merge 2 commits into
base: mael/jailfs-tests
Choose a base branch
from
Open

Conversation

arcanis
Copy link
Member

@arcanis arcanis commented Mar 10, 2024

Note

This PR is stacked on top of #6161

What's the problem this PR addresses?

Creating a folder mount requires a bit of non-trivial boilerplate. Not that much code, but a little tricky to remember.

How did you fix it?

Added two functions:

  • applyFsLayer applies a FakeFS<PortablePath> on top of the fs module.
  • MountFS.createFolderMount returns a MountFS that replaces all access to folder X by accesses to folder Y.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

Comment on lines +141 to +149
export function applyFsLayer(origFs: typeof fs, factory: (baseFs: FakeFS<PortablePath>) => FakeFS<PortablePath>) {
// We must copy the fs into a local, because otherwise
// 1. we would make the NodeFS instance use the function that we patched (infinite loop)
// 2. Object.create(fs) isn't enough, since it won't prevent the proto from being modified
const localFs = {...origFs};
const nodeFs = new NodeFS(localFs);

patchFs(fs, new PosixFS(factory(nodeFs)));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could find a way to avoid repeating those indirections when applying multiple mount layers ... perhaps by allowing MountFS to handle an array of mount configuration instead of a single one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant