Rename config.js to volumeconfig.js

This commit is contained in:
Girish Ramakrishnan
2014-06-19 20:02:00 -07:00
parent aae36c173f
commit b3cedab483
2 changed files with 25 additions and 25 deletions
+2 -2
View File
@@ -12,7 +12,7 @@ var fs = require('fs'),
ursa = require('ursa'),
async = require('async'),
util = require('util'),
Config = require('./config.js'),
VolumeConfig = require('./volumeconfig.js'),
safe = require('safetydance');
exports = module.exports = {
@@ -85,7 +85,7 @@ function Volume(id, options) {
this.mountPoint = this._resolveVolumeMountPoint();
this.tmpPath = path.join(this.mountPoint, 'tmp');
this.encfs = new encfs.Root(this.dataPath, this.mountPoint);
this.config = new Config(VOLUME_META_FILENAME, this.dataPath);
this.config = new VolumeConfig(VOLUME_META_FILENAME, this.dataPath);
}
Volume.prototype._resolveVolumeRootPath = function () {
+23 -23
View File
@@ -6,21 +6,21 @@ var mkdirp = require('mkdirp'),
path = require('path'),
safe = require('safetydance');
function Config(name, directory) {
assert(name && typeof name === 'string', 'Config needs a name for the config file.');
assert(directory && typeof directory === 'string', 'Config needs directory for the config file.');
function VolumeConfig(name, directory) {
assert(name && typeof name === 'string', 'VolumeConfig needs a name for the VolumeConfig file.');
assert(directory && typeof directory === 'string', 'VolumeConfig needs directory for the VolumeConfig file.');
this.store = {};
this.configDir = directory;
this.configFile = path.join(this.configDir, name + '.json');
this.VolumeConfigDir = directory;
this.VolumeConfigFile = path.join(this.VolumeConfigDir, name + '.json');
this.load();
}
Config.prototype.getFilePath = function () {
return this.configFile;
VolumeConfig.prototype.getFilePath = function () {
return this.VolumeConfigFile;
};
Config.prototype.get = function (key, defaultValue) {
VolumeConfig.prototype.get = function (key, defaultValue) {
var ret = defaultValue;
if (this.store.hasOwnProperty(key)) {
@@ -30,7 +30,7 @@ Config.prototype.get = function (key, defaultValue) {
if (typeof ret === 'object' && ret !== null) {
ret = safe.JSON.parse(JSON.stringify(ret));
if (!ret) {
console.error('Failed to copy the config value.', safe.error);
console.error('Failed to copy the VolumeConfig value.', safe.error);
ret = defaultValue;
}
}
@@ -38,14 +38,14 @@ Config.prototype.get = function (key, defaultValue) {
return ret;
};
Config.prototype.set = function (key, value) {
VolumeConfig.prototype.set = function (key, value) {
if (this.store[key] !== value) {
this.store[key] = value;
this.save();
}
};
Config.prototype.hset = function (key, field, value) {
VolumeConfig.prototype.hset = function (key, field, value) {
// do not overwrite old object
if (!this.store.hasOwnProperty(key)) {
this.store[key] = {};
@@ -59,12 +59,12 @@ Config.prototype.hset = function (key, field, value) {
return true;
};
Config.prototype.hget = function (key, field, defaultValue) {
VolumeConfig.prototype.hget = function (key, field, defaultValue) {
if (!this.hexists(key, field)) return defaultValue;
return this.store[key][field];
};
Config.prototype.hdel = function (key, field) {
VolumeConfig.prototype.hdel = function (key, field) {
if (!this.hexists(key, field)) return false;
delete this.store[key][field];
@@ -73,34 +73,34 @@ Config.prototype.hdel = function (key, field) {
return true;
};
Config.prototype.hexists = function (key, field) {
VolumeConfig.prototype.hexists = function (key, field) {
if (!this.store.hasOwnProperty(key)) return false;
if (typeof this.store[key] !== 'object') return false;
return this.store[key].hasOwnProperty(field);
};
Config.prototype.save = function () {
VolumeConfig.prototype.save = function () {
var that = this;
// ensure config folder
safe.safeCall(function () { mkdirp.sync(that.configDir); });
// ensure VolumeConfig folder
safe.safeCall(function () { mkdirp.sync(that.VolumeConfigDir); });
this.exists = true;
var data = safe.JSON.stringify(this.store, null, 4);
if (!safe.fs.writeFileSync(this.configFile, data)) {
console.error('Unable to save config file.', this.configFile, safe.error);
if (!safe.fs.writeFileSync(this.VolumeConfigFile, data)) {
console.error('Unable to save VolumeConfig file.', this.VolumeConfigFile, safe.error);
}
};
Config.prototype.load = function () {
var content = safe.fs.readFileSync(this.configFile);
VolumeConfig.prototype.load = function () {
var content = safe.fs.readFileSync(this.VolumeConfigFile);
this.store = safe.JSON.parse(content);
if (!this.store) {
debug('Unable to load config file', this.configFile, '. Using empty default.');
debug('Unable to load VolumeConfig file', this.VolumeConfigFile, '. Using empty default.');
this.store = {};
}
this.exists = true;
};
exports = module.exports = Config;
exports = module.exports = VolumeConfig;