Git Product home page Git Product logo

Comments (4)

G-Rath avatar G-Rath commented on May 10, 2024

I believe what you're wanting is a readonly mode - I've got plans to implement one when I have the bandwidth in the next month or so.

Unionfs will not create new folders for you automatically but if a fs is marked as read-only all methods that modify would instead throw (and thus cause unionfs to move onto the next fs or throw if it's the final fs).

I plan to expand the api of use:

const fs = new Union()
  .use(base, true)
  .use(vol)

fs.writeFileSync('/app/myfile'); // ENOENT
fs.mkdirSync('/app'); // create the folder in the vol fs
fs.writeFileSync('/app/myfile'); // OK

This should be pretty easy to implement, as it's just a matter of holding an object instead of just the fss:

class Unionfs {
  private ffs: Array<{
    fs: FileSystem;
    isReadonly: boolean;
  }> = []; // approx. type
}

from unionfs.

rixo avatar rixo commented on May 10, 2024

Readonly mode is a welcome addition because it can give total serenity that I won't pollute my shared volume; especially appreciable when it is the real fs.

It might also cover some of my use case because my test targets (bundlers like Rollup & Webpack) will probably create the parent directories recursively when they don't exist.

However, I still don't know how I can elegantly handle the situation where some of the parent directory hierarchy already exists in the parents fs, but not the "output" fs (which might start completely empty typically). Because, for example, the whole union might report that /path/to/app already exist, so the bundler will only try to mkdir /path/to/app/dist, and fail because /path/to/app exists only on the readonly fs...

I can probably mitigate on a case by case basis, by manually creating well known output directories for each targets, but I was hoping to be able to write a more generic tool. For example, I'd like to handle the case of plugins that also write to other locations, without having to know about every such plugin and where they might output their intermediary results...

Ideally I'd like to intercept any incoming write operation on the union, which would provide an opportunity for me to mirror existing directories from the parents on the last volume of the union, before letting the write operation complete with the same behaviour it would have on the real fs.

Is there a central method I can override to achieve this, or something to this effect? Or do you have any advice on how I could implement this behaviour?

from unionfs.

G-Rath avatar G-Rath commented on May 10, 2024

Readonly mode is a welcome addition because it can give total serenity that I won't pollute my shared volume; especially appreciable when it is the real fs.

That's exactly why I want it too 😂

Is there a central method I can override to achieve this, or something to this effect? Or do you have any advice on how I could implement this behaviour?

It sounds like you might want to use spyfs.

Ultimately, unionfs shouldn't create folders for you as that's a responsibility that belongs to the file system itself.

That's also a way you could work around this: replace fs with a Proxy that passes everything through to your unionfs, but that calls fs.mkdir with recursive: true on every path before hand should do the trick :)

Something like this should do:

new Proxy({}, {
  get(_, property: string): (...args: unknown[]) => unknown {
    return (...args: unknown[]) => {
      unionfs.mkdir(args[0], { recursive: true });

      return unionfs[property].call(args);
    }
  }
}

(That's off the top of my head, so it's probably somewhat wrong, but thats the basic shape you want)

from unionfs.

elmpp avatar elmpp commented on May 10, 2024

Hi @G-Rath, @streamich would be grateful if you cast a beady eye over my PR

from unionfs.

Related Issues (20)

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.