find-remove
find-remove copied to clipboard
invalid symlinks are never removed
The function fs.existsSync() used by find-remove returns false for invalid symlinks (see https://github.com/nodejs/node/issues/14025), that means that findRemoveSync() never removes them, no matter their age.
Hey @mariocarro Thanks for the great input.
Just released v5.1.0 on npm with this fix, which will also remove broken symlinks. For details, see this commit: https://github.com/binarykitchen/find-remove/commit/d0c0174a75a6dc78b5f1bb88611255f9ae1a3673
If you have any other ideas, feedback welcome anytime :)
Hello! Sorry for the late feedback... Anyway, it still doesn't remove my broken symlinks! The statSync at line 244:
try {
stat = fs.statSync(currentFile);
} catch (exc) {
// ignore
skip = true;
}
should be a lstatSync, isn't it? As it is now when processing an invalid symlink it an exception is thrown and the link is forcibly skipped instead of being removed.
Eeek, thanks for raising @mariocarro - fixed in v5.1.1 and published. LMK
Hi again. Version v5.1.1 still doesn't remove the broken symlinks!
There is one remaining statSync that needs to be replaced by an lstatSync, in the isOlder() function:
function isOlder(path: string, ageSeconds: number) {
if (!now) return false;
const stats = fs.statSync(path); // <== this should be lstatSync
const mtime = stats.mtime.getTime();
const expirationTime = mtime + ageSeconds * 1000;
return now > expirationTime;
}
This last change made the invalid symlinks finally go away.
@mariocarro Oh, thanks - why don't you make a Pull Request? Or want to become a co-maintainer of this package?