Skip to content

Commit

Permalink
wrap the saveFile method in a call to check if _data dir exists - #19
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jan 10, 2015
1 parent f9a0d89 commit 84efdad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 7 additions & 8 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function createDataDir (callback) {
});
}


function createDataDirIfNotExists (callback) {
dataDirExists(function(err, exists) {
if (!exists) {
Expand All @@ -44,19 +43,19 @@ function fileExists(record, callback) {
}

function saveFile(record, callback) {
var file = recordName(record);
record = JSON.stringify(record);
fs.writeFile(file, record, function(err) {
callback(err);
createDataDirIfNotExists( function() {
var file = recordName(record);
record = JSON.stringify(record);
fs.writeFile(file, record, function(err) {
callback(err);
});
});
}

module.exports = {
dataDirExists : dataDirExists,
createDataDir : createDataDir,
// deleteDataDir : deleteDataDir,
createDataDirIfNotExists : createDataDirIfNotExists,
fileExists : fileExists,
saveFile : saveFile,
// deleteFile : deleteFile
saveFile : saveFile
}
3 changes: 2 additions & 1 deletion lib/fs_delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function unlinkHandler(file, last, callback) {
callback(err, true);
});
} else {
// do nothing
// do nothing - stupid branch coverage.
}
});
}
Expand All @@ -41,6 +41,7 @@ function deleteDataDir (callback) {
});
}


module.exports = {
deleteDataDir : deleteDataDir
}

0 comments on commit 84efdad

Please sign in to comment.