function handleCallback(err) { if (err) { err.message += ` (${pkg.name}@${pkg.version})`; if (readstream.tarballFile && fs.existsSync(readstream.tarballFile)) { debug('[%s@%s] remove tarball file: %s, because %s', pkg.name, pkg.version, readstream.tarballFile, err); // remove tarball cache file fs.unlinkSync(readstream.tarballFile); } } if (!callback) { // ignore it return; } // ensure callback once const cb = callback; callback = null; cb(err); }
.then(_ => { fs.unlinkSync(paths.target) fs.renameSync(paths.tmp, paths.target) })