mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-26 17:01:04 +00:00
44 lines
855 B
CoffeeScript
44 lines
855 B
CoffeeScript
_ = require('lodash')
|
|
mkdirp = require('mkdirp')
|
|
errors = require('../_errors/errors')
|
|
|
|
# @nodoc
|
|
prefix = null
|
|
|
|
# Get current prefix
|
|
#
|
|
# @return {String} prefix
|
|
#
|
|
# @example Get prefix
|
|
# prefix = resin.data.prefix.get()
|
|
#
|
|
exports.get = ->
|
|
return prefix
|
|
|
|
# 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?
|
|
#
|
|
exports.set = (newPrefix, callback) ->
|
|
if not _.isString(newPrefix)
|
|
return callback?(new errors.InvalidPath(newPrefix))
|
|
|
|
mkdirp newPrefix, (error) ->
|
|
return callback?(error) if error?
|
|
prefix = newPrefix
|
|
return callback?()
|
|
|
|
# Clear prefix
|
|
#
|
|
# @example Clear prefix
|
|
# resin.data.prefix.clear()
|
|
exports.clear = ->
|
|
prefix = null
|