inky icon indicating copy to clipboard operation
inky copied to clipboard

Create unique temp directories and clean up afterwards

Open SpoonMeiser opened this issue 4 years ago • 4 comments

Use os.tmpdir and fs.mkdtemp to create a uniquely named temporary directory in the correct place.

Also attempt to remove the temporary directory on application exit. This uses fs.rmSync which is only available in Node 14, which might be too new.

SpoonMeiser avatar Oct 03 '21 00:10 SpoonMeiser

Thanks for this! I have a couple of questions, if you don't mind?

  • We've had some issues with with temporary directories in the past since it's platform dependent. Can I ask what platform(s) you've tested on?
  • When you say that fs.rmSync is only available in Node 14 which may be too new. Did it work for you when you tested? Any reason to believe it won't work otherwise? Our version of Electron is super outdated so I wouldn't be surprised if we had issues with APIs being too new!

joethephish avatar Oct 04 '21 09:10 joethephish

Unfortunately I'm only able to test on Linux

Instead of using rmSync, I could add another npm dependency for a package that does the same in older versions of node (at least one page recommended del) if that is acceptable?

The behaviour if the function doesn't exist is an error message in the console, and the directory not being deleted, which isn't very different from the current behaviour, although potentially more annoying to manually cleanup now if there are multiple temp directories lying about.

SpoonMeiser avatar Oct 04 '21 10:10 SpoonMeiser

I've added a new commit that adds del as an additional dependency, and uses this to delete the temp directory. This should work with older versions of node.

SpoonMeiser avatar Oct 05 '21 19:10 SpoonMeiser

Also, although this replaces the changes from https://github.com/inkle/inky/pull/223, I did test that this does still respect TMPDIR on Linux (and I assume also OSX)

SpoonMeiser avatar Oct 12 '21 00:10 SpoonMeiser