Skip to content

Commit

Permalink
Wip fix sindresorhus#20
Browse files Browse the repository at this point in the history
  • Loading branch information
forivall committed Oct 16, 2014
1 parent 3650c86 commit 1ff21ce
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ Configstore.prototype = Object.create(Object.prototype, {
all: {
get: function () {
try {
return yaml.safeLoad(fs.readFileSync(this.path, 'utf8'), {
var all = yaml.safeLoad(fs.readFileSync(this.path, 'utf8'), {
filename: this.path,
schema: yaml.JSON_SCHEMA
});
if (all == null) {
throw new Error('yaml.safeLoad returned undefined');
}
return all;
} catch (err) {
// create dir if it doesn't exist
if (err.code === 'ENOENT') {
Expand All @@ -60,11 +64,11 @@ Configstore.prototype = Object.create(Object.prototype, {
try {
// make sure the folder exists, it could have been
// deleted meanwhile
mkdirp.sync(path.dirname(this.path), defaultPathMode);
var createdDir = mkdirp.sync(path.dirname(this.path), defaultPathMode);
fs.writeFileSync(this.path, yaml.safeDump(val, {
skipInvalid: true,
schema: yaml.JSON_SCHEMA
}), writeFileOptions);
}), createdDir ? assign({ flag: 'wx' }, writeFileOptions) : writeFileOptions);
} catch (err) {
// improve the message of permission errors
if (err.code === 'EACCES') {
Expand Down

1 comment on commit 1ff21ce

@forivall
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just quickly whipped this up in the github editor. I need to see if it'll work!

Please sign in to comment.