Code Monkey home page Code Monkey logo

Comments (3)

yalue avatar yalue commented on May 23, 2024

Thanks for the feedback! True, it would be nice to have. The hard part, of course, is supporting merging the results of Glob into a single list for patterns that match content in both underlying FS's. Perhaps code like the following wouldn't be that bad:

func (m *MergedFS) Glob(pattern string) ([]string, error) {
    contentsA, _ := fs.Glob(m.A, pattern)
    contentsB, _ := fs.Glob(m.B, pattern)
    
    // The key would be making this as efficient as possible
    results := mergePathLists(contentsA, contentsB)
    return results, nil
}

Using fs.Glob would take care of the optimized calls if either underlying FS implemented GlobFS. The main issue is whether the "mergePathLists" code would be faster than just letting the default fs.Glob invoke the existing directory merging code. Based on intuition, I'd expect it to be an improvement even with a naive implementation of mergePathLists, but I'd like to have a BenchmarkGlobFSPerformance test (or something like that) when adding such a feature.

I can probably add something like this in a few days, but I'd be happy to take any suggestions or PRs if you want to work on it yourself.

from merged_fs.

yalue avatar yalue commented on May 23, 2024

I was thinking about this more, and it's a bit more complicated than I realized when writing my earlier comment. That snippet actually wouldn't work. Glob could actually list contents of directories that ought not to be "visible."

Imagine the following scenario:

  • We are merging FSs A and B, with A having higher priority.
  • A contains a regular file, 'x'
  • B contains a directory x, with some content. Say, 'x/1.txt', and 'x/2.txt'.
  • We call fs.Glob(merged, "x/*.txt")

The correct results of the pattern "x/*.txt" in the above scenario ought to be nothing at all, since the merged FS shows "x" as a regular file rather than a directory. However, the implementation in my earlier comment would return "x/1.txt" and "x/2.txt"--files you wouldn't be able to Open in the merged FS.

I actually added a test case to check for this in commit c2f37d0. (test_a.zip contains a regular file named 'a', which is a directory in test_b.zip, and the new TestGlob contains code to ensure that a/* won't return the contents of the directory.

An optimization is still likely possible, but it would likely require checking each file to make sure it isn't in an unreachable directory, perhaps using the existing validatePathPrefix function.

from merged_fs.

yalue avatar yalue commented on May 23, 2024

Closing for now, may reopen in the future if I can think of a good approach.

from merged_fs.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.