Node occasionally gives multiple files/folders the same inode #12115
Closed
Description
opened on Mar 29, 2017
Moderator's note (@Fishrock123): Off-topic comments have and will be deleted.
- Version: v7.2.1
- Platform: Windows 10 Pro 64bit, Windows 7 Enterprise 64bit (Both using NTFS)
- Subsystem: File System
Node sometimes reports different files/folders to have identical ino values.
I can't reproduce this consistently and copying/reproducing a folder structure that contains dupes elsewhere doesn't replicate the issue.
I did encounter lots of duplicates under C:\Users\%USER%\AppData
but it may be different for other people
Example
Specific example I encountered
# Structure
│ ServerStore.jsx
│
├───constants
│ Api.jsx
│
└───stores
UserStore.jsx
> fs.lstatSync("stores").ino
5910974511014218
> fs.lstatSync("stores/UserStore.jsx").ino
24206847997202570
> fs.lstatSync("constants").ino //Duplicate
9851624184963316
> fs.lstatSync("constants/Api.jsx").ino //Duplicate
9851624184963316
> fs.lstatSync("ServerStore.jsx").ino
3659174697792238
Test Script
Here's a hacky node script to loop through a directory and look for duplicate inodes.
Running it on most of my other folders didn't yield a result, until I ran it on C:\Users\%USER%\AppData
where I encounted loads of duplicates
Usage: node dupe.js [dir]
var fs = require('fs');
var path = require('path');
var process = require('process');
// Recursively walks a directory and looks for duplicate inodes
// loop from http://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search
var dir = process.argv[2];
if (dir == undefined) {
dir = '.';
}
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var pending = list.length;
if (!pending) return done(null, results);
list.forEach(function(file) {
file = path.resolve(dir, file);
fs.stat(file, function(err, stat) {
if(stat && stat.ino) {
results.push({
file: file,
ino: stat.ino
});
}
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
if(res) {
results = results.concat(res);
}
if (!--pending) done(null, results);
});
}
else {
if (!--pending) done(null, results);
}
});
});
});
};
walk(dir, function(err, results) {
var merge = {};
results.forEach(function(it) {
if (!merge[it.ino]) {
merge[it.ino] = [];
}
merge[it.ino].push(it.file);
});
var dupes = Object.keys(merge).filter(key => merge[key].length > 1);
dupes.forEach(it => console.log(it, merge[it]));
})
Activity