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

fs.readFile reads wrong file after renaming parent dir #282

Closed
Nishkalkashyap opened this issue Dec 16, 2018 · 4 comments
Closed

fs.readFile reads wrong file after renaming parent dir #282

Nishkalkashyap opened this issue Dec 16, 2018 · 4 comments

Comments

@Nishkalkashyap
Copy link

Steps to reproduce :

  1. fs.mkdirSync('/dir');

  2. fs.writeFileSync('/dir/file.ext');

  3. fs.readFileSync('/dir/file.ext');
    //returns Buffer[]

  4. fs.renameSync('/dir/file.ext', '/dir/newfile.ext');

  5. fx.readFileSync('/dir/newfile.ext');
    // Throws Error

Error: ENOENT: no such file or directory, open '/dir/file.ext'

Even though new file name is entered in readFileSync, it still tries to look for the old file?

@streamich
Copy link
Owner

streamich commented Dec 16, 2018

If in step 5 you rename fx to fs, does it work?

This works for me

var fs = require("memfs")

fs.mkdirSync('/dir');
fs.writeFileSync('/dir/file.ext', 'asdf');
fs.readFileSync('/dir/file.ext');
fs.renameSync('/dir/file.ext', '/dir/newfile.ext');

console.log(fs.readFileSync('/dir/newfile.ext', 'utf8'));

@falkenhawk
Copy link

@streamich try this reproduction, please: 🙏

const fs = require('memfs');

fs.mkdirSync('dir', { recursive: true });
fs.writeFileSync('dir/file.ext', 'asdf');

fs.renameSync('dir', 'newdir');
fs.readFileSync('newdir/file.ext', 'utf8');

Still tries to read from the old path:

Error: ENOENT: no such file or directory, open '/(...)/dir/file.ext'

Note: it works just fine with const fs = require('fs');

@falkenhawk
Copy link

Also note: statSync('newdir/file.ext'), accessSync, existsSync all work fine after rename!
But vol.toJSON() still lists the file under the "old" path:
{ '/(...)/dir/file.ext': 'asdf' }

@G-Rath
Copy link
Collaborator

G-Rath commented Nov 3, 2022

@falkenhawk your reproduction works fine for me using the latest version of memfs so I'm going to close this as hopefully its been fixed - feel free to open a new issue if you have any further problems.

@G-Rath G-Rath closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2022
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

4 participants