balena-cli/lib/resin/data/data-prefix.coffee

44 lines
854 B
CoffeeScript
Raw Normal View History

2014-12-09 09:05:37 -04:00
_ = require('lodash')
mkdirp = require('mkdirp')
2014-12-09 09:05:37 -04:00
errors = require('../errors/errors')
2014-11-07 12:42:02 -04:00
2014-12-05 14:11:45 -04:00
# @nodoc
2014-11-07 12:42:02 -04:00
prefix = null
2014-12-05 14:11:45 -04:00
# Get current prefix
#
# @return {String} prefix
#
# @example Get prefix
# prefix = resin.data.prefix.get()
#
2014-11-07 12:42:02 -04:00
exports.get = ->
return prefix
2014-12-05 14:11:45 -04:00
# Set prefix
#
# @param {String} newPrefix new prefix
# @param {Function} callback callback (error)
#
# @throw {Error} Will throw if prefix is not a valid path
#
# @example Set prefix
# resin.data.prefix.set '/opt/resin', (error) ->
# throw error if error?
#
2014-11-17 15:20:19 -04:00
exports.set = (newPrefix, callback) ->
2014-12-09 09:05:37 -04:00
if not _.isString(newPrefix)
return callback?(new errors.InvalidPath(newPrefix))
2014-11-07 12:42:02 -04:00
mkdirp newPrefix, (error) ->
return callback?(error) if error?
prefix = newPrefix
return callback?()
2014-11-07 12:42:02 -04:00
2014-12-05 14:11:45 -04:00
# Clear prefix
#
# @example Clear prefix
# resin.data.prefix.clear()
2014-11-07 12:42:02 -04:00
exports.clear = ->
prefix = null