node-tmp icon indicating copy to clipboard operation
node-tmp copied to clipboard

`tmp` should use `{ recursive: true }` when available with `unsafeCleanup: true`

Open hasezoey opened this issue 3 years ago • 4 comments

Operating System

any

NodeJS Version

12.10.0 - 14.14.0 | 14.14.0+

Tmp Version

0.2.1

Expected Behavior

when unsafeCleanup: true tmp should use nodejs native recursive delete when available, { recursive: true } for rmdir(Sync) is available since nodejs 12.10.0, until 14.14.0, where rm(Sync) should be used with { recursive: true }

reference: https://nodejs.org/api/fs.html#fsrmdirsyncpath-options

Experienced Behavior

uses rimraf for deleting files when unsafeCleanup: true is set, which sometimes (at least for me) results in removeCallback not actually being sync to deleting the directory

hasezoey avatar Jun 09 '22 06:06 hasezoey

Thanks for the report @hasezoey.

In the past, I first tested the { recursive: true } option, however, I turned out that it would sometimes fail or did not behave in the way we needed it to, with the then available node version. That is why we, reluctantly, incorporated rimraf.

I will see what this option does now and whether it behaves the way we need it to.

silkentrance avatar Aug 25 '22 14:08 silkentrance

As for the removeCallback not being in sync is a question of the OS you are working under. Windows will lock open files and thus prevent rmdir from removing the directories these files are located in. Sometimes, this goes as far as that node has to be shutdown prior to the lock being removed, leaving all directories in place, and one has to manually clean up the temporary storage.

silkentrance avatar Aug 25 '22 14:08 silkentrance

Windows will lock open files and thus prevent rmdir from removing the directories these files are located in.

just for information, i am on Linux, so they should be unlinked if not directly removed (which recursively deleting (at least rm -rf) does)

hasezoey avatar Aug 25 '22 14:08 hasezoey

Thanks for the information. I will see what I can do.

silkentrance avatar Aug 25 '22 14:08 silkentrance

rimraf works for me and also in the automated tests

please provide a more specific scenario in which this will not work.

silkentrance avatar Jun 08 '24 16:06 silkentrance