memfs
memfs copied to clipboard
fs.readFile reads wrong file after renaming parent dir
Steps to reproduce :
-
fs.mkdirSync('/dir');
-
fs.writeFileSync('/dir/file.ext');
-
fs.readFileSync('/dir/file.ext');
//returns Buffer[] -
fs.renameSync('/dir/file.ext', '/dir/newfile.ext');
-
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?
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'));
@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');
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' }
@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.