find-remove icon indicating copy to clipboard operation
find-remove copied to clipboard

invalid symlinks are never removed

Open mariocarro opened this issue 9 months ago • 5 comments

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.

mariocarro avatar Feb 23 '25 15:02 mariocarro

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 :)

binarykitchen avatar Feb 25 '25 07:02 binarykitchen

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.

mariocarro avatar Mar 05 '25 13:03 mariocarro

Eeek, thanks for raising @mariocarro - fixed in v5.1.1 and published. LMK

binarykitchen avatar Mar 06 '25 06:03 binarykitchen

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 avatar Mar 11 '25 13:03 mariocarro

@mariocarro Oh, thanks - why don't you make a Pull Request? Or want to become a co-maintainer of this package?

binarykitchen avatar Mar 12 '25 06:03 binarykitchen