fs = require 'fs'

exports.getNewDirName = () ->
  rand = Math.floor Math.random() * 100000000
  path = "/tmp/log"
  path = path.concat rand.toString()
  path = path.concat "/"

deletePath_ = (path, callback) ->
  fs.rmdir path, (err) ->
    throw err if err
    callback err

deleteFilesInPath_ = (path, callback) ->
  fs.readdir path, (err, files) ->
    throw err if err
    if files.length != 0
      lastFile = files[files.length - 1]
      fs.unlink path + lastFile, (err) ->
        throw err if err
        deleteFilesInPath_ path, callback
    else
      deletePath_ path, callback

exports.deleteFilesInPath = (path, callback) ->
  deleteFilesInPath_ path, callback
