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

Constructing a memfs from an osfs. #57

Open
elldritch opened this issue Apr 7, 2018 · 2 comments
Open

Constructing a memfs from an osfs. #57

elldritch opened this issue Apr 7, 2018 · 2 comments

Comments

@elldritch
Copy link

I have an interesting use case where I have some functions that run over a billy.Filesystem and I want to run them on a directory while ignoring a specific file. Ideally, I'd be able to do this without modifying the functions and without modifying the underlying filesystem. Instead, I want to construct a memfs from an osfs, and then delete the ignored file from the memfs so I can run the function on the memfs without needing to modify this.

Is this functionality difficult to implement? I couldn't find documentation on the best way to do this.

@smola
Copy link
Contributor

smola commented Apr 9, 2018

There are some options here:

  • Implement an utility function that copies a directory recursively from one file system to another.
  • Implement a copy-on-write filesystem that wraps two underlying filesystems. A read-only layer (osfs in your case) and a writeable layer (memfs in your case). This would allow you to access osfs without copying it to memfs. This also works for cases where you modify files, not just delete. Afero has an implementation of this that can guide you on the implementation.
  • Implement something like a masking fs wrapper. That is, a filesystem that is constructed with an underlying filesystem, include glob expressions and exclude glob expressions. With this, you could wrap your osfs with it, excluding the file you don't want.

None of these are currently implemented in go-billy. I guess these might be accepted for the helper or util subpackages, but that's something to be discussed with @mcuadros.

@ilius
Copy link

ilius commented Oct 19, 2022

Implement something like a masking fs wrapper. That is, a filesystem that is constructed with an underlying filesystem, include glob expressions and exclude glob expressions. With this, you could wrap your osfs with it, excluding the file you don't want.

"exclude glob expressions" part sounds like a commonly used pattern, kinda like .gitignore. I'm willing to try implementing this.

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

No branches or pull requests

3 participants