#[nexe pkg] existsSync returns true even if the folder is deleted after the first existsSync check
69 messages · Page 1 of 1 (latest)
Good morning @heady rampart , becuase of a bug with fs, it's not able to delete directories
No, it’s not. If you are using child process, fs isn’t involved at all
this is the bug that I am facing with the fs
I check if the dir exists, then proceed with the shell command to delete the folder, then I run check if the dir exists, those checks still giving me that the dir exists even if it's not when I check it on the side
Okay, so you have two threads for the same issue, I’m closing this one
no, this thread is about existsSync
The other one is focused on deleting meanwhile this one is focused on checking if directory exists
There is no fs cache, everything is a direct libuv call
Again, you are trying to perform a non standard operation, deleting files with a command, not fs
It’s an issue with the command, it’s probably slower than the file read
Try using Node.js’s file system instead of child process
Either way if I delete whether internally or externally, if the file doesn't exist, then existsSync shouldn't return true, at the end of the day, they are all separate things
Ok, let's put it this way, I have an ongoing process or job that runs every while, if a folder is deleted by user, then should it still return true? So, we can't really link both together
I suppose, and I’m not an expert on the file system, If you delete a folder externally, and you call fs in the same ‘tick’ it might return true instead of false.
and you call fs in the same ‘tick’ it might return true instead of false.
What do you mean by same 'tick'? Is this about same timing?
Well, the event loop has an order, if you are deleting the file at the same time that you are checking if it exists, there might be a discrepancy
After folder is deleted, I have a loop that runs a 10 second wait on each iteration and existsSync to see the response feedback, I can see true every single time for 100 seconds split by 10 iterations, the folder does not exist when I checked during the checks period. So, no it's not a timing issue.
you are definitely doing something wrong if it still says it exists 100 seconds after it was deleted.
Have you tried other methods to check if the file exists in libuv? Do they fail?
@bright spade , can you please clarify? The situation is pretty much straight forward on my side:
if (existsSync(folderPath)) {
deleteSync(folderPath);
}
for (let i = 0; i < 10; i++) {
if (!existsSync(folderPath)) {
break;
}
const ms = (i + 1) * 1000;
this.logger.info(`${folderPath} still exists, waiting ${ms} milliseconds`);
await ThreadHelper.sleep(ms); // I can validate the folder is not there anymore
}
Node version: v22.21.0
Yes, I already migrated to use spawnSync at the moment, waiting on verification later today.
what is deleteSync?
It's described here #1434751224712003584 message , but this shouldn't be related, a folder no longer exists then existsSync should return false
if you're already using modules (or in an async IIFE), why are you using the sync methods?
I'm not reading that mess. that is 100% unnecessary
use unlink. be done
I wish @bright spade , but I have to, there is a clear bug in rmSync and native fs functions
unlink doesn't remove recursive folders
sorry, rm
it's there, and it fails
if (pathStats.isDirectory()) {
rmSync(path, {
force: true,
recursive: true
});
} else {
unlinkSync(path);
}
} catch (rmEx) {
logger?.warn(`Failed to delete ${path}, resolving to removeSync due to ${(rmEx as Error).message}`);
try {
removeSync(path);
} catch (removeEx) {
logger?.warn(`Failed to delete ${path}, resolving to rimraf due to ${(removeEx as Error).message}`);
Fails on my end all of them
how can I "just delete" when rmSync, removeSync and even rimraf fail?
they don't fail...
I will repeat myself again, they do fail on my side. See the other thread for their issue, please let us keep this thread about existsSync
why don't you look at that thread instead? you were told why you get that error. it's user error
Can we please keep this thread about existsSync, please post your questions there in the other thread
you're using like 20 different fs libraries and crap
this is such a convoluted mess for zero reason
I have no questions. this is an XY problem. you're doing something wrong. good luck!
The reason there are 20 different fs libraries is to demonstrate that none works, now if you don't want to understand or comprehend that it's not working on my side and failing, that's your problem, pls get off this thread, thanks
if 20 different libraries don't work, wouldn't you guess the problem is elsewhere instead of just putting together this pointless mess and asking questions that don't make sense?
because they all fail with the same error, pls get off this thread
this question should be closed. there is no fs cache. you are doing something wrong if files are not being deleted when you use proper methods
existsSync returns true even if the folder is deleted after the first existsSync check
Heya! I’ve read over @bright spade’s lovely help for you, and I agree this thread should be closed.
as mentioned, the original problem was solved (there’s no fs cache), and the rest of the question isn’t something we can help you with here, as.
- This is an XY problem. https://xyproblem.info
- You already have a thread open, which, within itself, is an XY problem
- We’ve answers your original question
- you haven’t been really receptive to our answers. If
node:fstells you the file exists, that means thatlibuvthinks the file exists. Iflibuvthinks the file exists, I’m pretty sure it exists, and plenty of libraries would probably agree (https://github.com/libuv/libuv/blob/v1.x/LINKS.md)
Reopened following #help-chat message
I delete a folder using spawnSync command, and I can verify that the folder is deleted
how are you deleting the folder, and how are you verifying? have you tried other tools that use libuv to cross-check, as mentioned above?
@trim silo , after I run deleteSync mentioned above and deleted the folder using shell rm command as the other functions by nodeJS are failing, that code runs (see the message referenced), as it waits seconds and logs "folder still exists", I can in the same time run ls in my terminal and verify that it's deleted and also via finder (as I am using macos)
as the other functions by nodeJS are failing
could you clarify what you mean by that?
This is where we will cross-issue here with https://discord.com/channels/425824580918181889/1434751224712003584 , what I am seeing is either that there is a critical bug in the nodejs filesystem, cuz the older versions didn't have this issue. This issue started to happen since v22.21.0+ (I am currently on 24.11.0)
In this thread, I just want to focus on existsSync
the code you linked back to is still referencing a lot of extra stuff (deleteSync, mainly, but the others as well)
could you make an mcve?
I am working on this at the moment.
I am not able to reproduce this outside nexe package, I found this bug report here https://github.com/nexe/nexe/issues/639 this is what I am experiencing as well exactly for the existsSync.
could it possibly be something to do with nexe then?
It is, I can confirm 100% now.
But why node version made a difference, this is very strange issue!
[nexe pkg] existsSync returns true even if the folder is deleted after the first existsSync check
I can probably answer that for you: Node.js moved for fs ‘stuff’ to C++ in recent versions, so any JS voodoo Nexe applied wouldn’t really matter.
(I assume)
maybe, I don't know @heady rampart , I have just migrated from using existsSync to shell command using spawnSync and it works like a charm, at this moment nexe + this new change (if you are correct) are broken