binarykitchen / find-remove

recursively finds files by filter options from a start directory onwards and deletes these. useful if you want to clean up a directory in your node.js app.
https://npmjs.org/package/find-remove
61 stars 19 forks source link

Odd behavior with limit #33

Open hardysabs2 opened 2 years ago

hardysabs2 commented 2 years ago
const result = findRemoveSync(process.env.LOG_BASE_DIR, {
  age: { seconds: process.env.SECONDS_TO_RETAIN_LOG_FILES },
  extensions: ".log",
  limit: 100
});

the base dir has multiple directories under it and the log files are under those. If I have counted right there are around 94 files scattered amongst sub-folders, all *.log, definitely not many more than 100 if at all. All old than the 20s set and it seems to take 2 goes to delete all the files.

I have checked around to see that none of the files are open anywhere. Is there anything else that I may be doing wrong that may be causing this? What is the behavior if it fails to delete one file, will it still go on to delete the others?

Thanks

binarykitchen commented 2 years ago

Thanks for bringing this to my attention.

Busy family father here. If you could fork this repository, display this problem in a new failing unit test case, that would be great :)

binarykitchen commented 2 years ago

I think we already have some unit tests toward the end covering some deeply, nested random files. Have a look. I hope this helps.