Skip to content

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

@Streemo

Description

@Streemo

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))
      }
    }
  })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions