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

43 lines
837 B
CoffeeScript
Raw Normal View History

mkdirp = require('mkdirp')
2014-11-26 18:22:01 +00:00
fsUtils = require('./fs-utils/fs-utils')
2014-11-07 16:42:02 +00:00
2014-12-05 18:11:45 +00:00
# @nodoc
2014-11-07 16:42:02 +00:00
prefix = null
2014-12-05 18:11:45 +00:00
# Get current prefix
#
# @return {String} prefix
#
# @example Get prefix
# prefix = resin.data.prefix.get()
#
2014-11-07 16:42:02 +00:00
exports.get = ->
return prefix
2014-12-05 18:11:45 +00: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 19:20:19 +00:00
exports.set = (newPrefix, callback) ->
2014-11-07 16:42:02 +00:00
if not fsUtils.isValidPath(newPrefix)
2014-11-17 19:20:19 +00:00
return callback?(new Error('Invalid path'))
2014-11-07 16:42:02 +00:00
mkdirp newPrefix, (error) ->
return callback?(error) if error?
prefix = newPrefix
return callback?()
2014-11-07 16:42:02 +00:00
2014-12-05 18:11:45 +00:00
# Clear prefix
#
# @example Clear prefix
# resin.data.prefix.clear()
2014-11-07 16:42:02 +00:00
exports.clear = ->
prefix = null