Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API feature request: tmp.forceCleanup([...names]) #172

Closed
Streemo opened this issue May 21, 2018 · 3 comments
Closed

API feature request: tmp.forceCleanup([...names]) #172

Streemo opened this issue May 21, 2018 · 3 comments

Comments

@Streemo
Copy link

Streemo commented May 21, 2018

Apparently, node-tmp doesn't properly cleanup in some situations. It would be nice to have a method on tmp like this:

tmp.forceCleanup = (names, cb) => {
  if (!names) return tmp._cleanupAllCreatedFilesAndDirs(cb);
  // run cleanup jobs in parallel, calls cb when all are done
  parallel(names.map(name => done => tmp._cleanupFileOrDir(name, done)), cb)
}

usage:

const tmp = require("tmp")

process.on("SIGINT", () => tmp.forceCleanup())

// my code ...

what i'll probably do currently (a hack...):

const tmp = require("tmp")
const fs = require("fs")
const { join } = require("path")

// keep track of all created crap, or if you use a single parent dir:
// delete all stuff under parent dir that starts with tmp-

process.on("SIGINT", () => {
  fs.readdir(parentDir, (err, files) => {
    //handle err
    for (let file of files){
      if (file.slice(0,4) === "tmp-"){
        // brevity (no err handling/file checking)
        fs.unlink(join(parentDir, file))
      }
    }
  })
})
@silkentrance
Copy link
Collaborator

silkentrance commented May 22, 2018

@Streemo which version of node and tmp are you using, which OS?

Normally, this should be handled automatically when you call tmp.setGracefulCleanup(), see https://github.com/raszi/node-tmp#graceful-cleanup

Otherwise, and this is for debugging, it will keep the temporary files on process exit.

@Streemo
Copy link
Author

Streemo commented May 22, 2018

node: 10.1.0
npm: 6.0.1
tmp: 0.0.33
os: MacOS 10.13.2 (high sierra)

The problem was that (even if setGracefulCleanup was called), CTRL+C would not actually remove the tmp folders. The folders would be removed on process' natural exit, though. I think setGracefulCleanup should try to remove all the junk created on any kind of exit (whether CTRL+C or natural exit, etc. but that's just my preference. Maybe a distinction between fullCleanup/forceCleanup and naturalCleanup for debugging purposes?

@silkentrance
Copy link
Collaborator

@Streemo so this is basically a dupe of #121. Closing. Feel free to try out the PR for #121: #159.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants