src-d / go-billy

The missing interface filesystem abstraction for Go
https://godoc.org/gopkg.in/src-d/go-billy.v4
Apache License 2.0
199 stars 43 forks source link

Constructing a `memfs` from an `osfs`. #57

Open elldritch opened 6 years ago

elldritch commented 6 years ago

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 commented 6 years ago

There are some options here:

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 commented 2 years ago

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.