[api fix] Dont eagerly create config files in .load()
and .loadSync()
This commit is contained in:
parent
021850a14d
commit
bbcb2712f1
1 changed files with 22 additions and 33 deletions
|
@ -81,15 +81,9 @@ File.prototype.load = function (callback) {
|
||||||
|
|
||||||
path.exists(self.file, function (exists) {
|
path.exists(self.file, function (exists) {
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
//
|
return callback(null, {});
|
||||||
// If the path we are attempting to load doesn't exist, create it
|
|
||||||
//
|
|
||||||
self.save({}, function (err) {
|
|
||||||
self.store = {};
|
|
||||||
return callback(err, self.store);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
//
|
//
|
||||||
// Else, the path exists, read it from disk
|
// Else, the path exists, read it from disk
|
||||||
//
|
//
|
||||||
|
@ -107,23 +101,18 @@ File.prototype.load = function (callback) {
|
||||||
|
|
||||||
callback(null, self.store);
|
callback(null, self.store);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// ### function load (callback)
|
// ### function loadSync (callback)
|
||||||
// #### @callback {function} **Optional** Continuation to respond to when complete.
|
// Attempts to load the data stored in `this.file` synchronously
|
||||||
// Attempts to load the data stored in `this.file` synchronously and responds appropriately.
|
// and responds appropriately.
|
||||||
//
|
//
|
||||||
File.prototype.loadSync = function () {
|
File.prototype.loadSync = function () {
|
||||||
var data, self = this;
|
var data, self = this;
|
||||||
|
|
||||||
if (!path.existsSync(self.file)) {
|
if (!path.existsSync(self.file)) {
|
||||||
//
|
|
||||||
// If the path we are attempting to load doesn't exist, create it
|
|
||||||
//
|
|
||||||
self.saveSync({});
|
|
||||||
self.store = {};
|
self.store = {};
|
||||||
data = {};
|
data = {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue