Comments (4)
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.
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.
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.
Hi @G-Rath, @streamich would be grateful if you cast a beady eye over my PR
from unionfs.
Related Issues (20)
- support fs Pomise API HOT 1
- The automated release is failing 🚨 HOT 46
- no type file? HOT 2
- readdir fails with error when one of the fs fails HOT 1
- ufs.createWriteStream(path) results in Error: ENOENT: no such file or directory, stat HOT 1
- `ufs.createWriteStream` fails when folder exists but file does not HOT 2
- `ufs.copyFileSync` fails when src and destination folders exist in separate volumes HOT 1
- [RFC] Downstream projects HOT 1
- memfs volume not compatible with 'use' method HOT 2
- Missing licence in package.json HOT 1
- Action Required: Fix Renovate Configuration
- Document on the order of operations on underlay file systems HOT 1
- `fs.constants` is undefined
- Dependency Dashboard
- Setup automatic releases for CI & rename default branch
- Suggestion: unionFS.promises.use() HOT 3
- Upgrade fs-monkey dependency HOT 1
- Broken package 4.5.0 - missing lib files HOT 2
- The automated release is failing 🚨 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unionfs.