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

toJson for links #359

Open
amitgilad3 opened this issue Apr 4, 2019 · 2 comments
Open

toJson for links #359

amitgilad3 opened this issue Apr 4, 2019 · 2 comments

Comments

@amitgilad3
Copy link

when i create a volume with a link and then convert that volume into a json the link is turned into an actual file so when i load that json into a new volume it is no longer a link.

example

const { fs, Volume } = require('memfs');
const vol = new Volume;

vol.mkdirSync('/tmp/');
vol.writeFileSync('/tmp/bar','bar!!!')
vol.linkSync( '/tmp/bar', '/app');

console.log(vol.toJSON()) //{/tmp/bar: "bar!!!", /app: "bar!!!"}
vol.writeFileSync('/tmp/bar', 'kutner')
console.log(vol.toJSON()) //{/tmp/bar: "kutner", /app: "kutner"}


const vol2 = Volume.fromJSON(vol.toJSON());
console.log(vol2.toJSON()) //{/tmp/bar: "kutner", /app: "kutner"}
vol2.writeFileSync('/tmp/bar', 'amit')
console.log(vol2.toJSON())//{/tmp/bar: "amit", /app: "kutner"}

any ideas?

@pizzafroide
Copy link
Contributor

Well, that's part of a larger issue that I want to address for a while (but had no time for this the last few months). The problem is in fact that toJSON function only exports the files content, and fromJSON is only able to 'mount' regular files and directories. I agree that toJSON (and fromJSON) should be able to export/import the whole files, that is their content and properties (type, ownership, permissions, times, and so forth). This would be a breaking change for some people though. I'm thinking of those who use Jest snapshots for instance. So this change should come with a way of configuring the current UID, GID, and times (among other things I guess). Because it should be possible to have a toJSON output independent from the current user, time, or machine. First and foremost, maybe adding options to toJSON function would suffice for this particular aspect of the issue. But I think that adding the ability to configure memfs would also be needed rather rapidly.

Anyway, help (and PR) are welcome! 😃

@streamich
Copy link
Owner

streamich commented Apr 8, 2019

@vjpr has suggested that this advanced export/import functionality could even be a separate module, so it can be used with real fs, as well as with memfs.

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