All files utils.js

100% Statements 17/17
90% Branches 9/10
100% Functions 2/2
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 294x 4x 4x   4x 4x   4x   4x 3x 3x 1x 1x 1x     2x 2x   1x       4x        
const fs = require('fs')
const uuidv1 = require('uuid/v1')
const config = require('config')
 
const logger = (config && config.logger) || console
const tempDir = (config && config.minioTmpDir) || '/tmp'
 
const getTempPath = filename => `${tempDir}/${filename}.${uuidv1()}`
 
const removeFile = tmpFile => {
  const regex = new RegExp(`^${tempDir}/`)
  if (!tmpFile || !tmpFile.match(regex)) {
    const errMsg = `Invalid file: ${tmpFile}`
    logger.warn(errMsg)
    throw new Error(errMsg)
  }
 
  try {
    fs.unlinkSync(tmpFile)
  } catch (err) {
    logger.info(`${tmpFile} not deleted: ${err}`)
  }
}
 
module.exports = {
  getTempPath,
  removeFile
}