diff --git a/expire-channels.js b/expire-channels.js index a42a3af58..f7597b323 100644 --- a/expire-channels.js +++ b/expire-channels.js @@ -60,7 +60,7 @@ var handleTask = function (str, path, cb) { } }).nThen(function () { // remove the task file... - Fs.unlink(path, function (err) { + Fs.unlink(path, function (err) { // FIXME deletion if (err) { console.error(err); } cb(); }); diff --git a/storage/file.js b/storage/file.js index e4a746a67..46ae366a6 100644 --- a/storage/file.js +++ b/storage/file.js @@ -2,6 +2,7 @@ /* jshint esversion: 6 */ /* global Buffer */ var Fs = require("fs"); +var Fse = require("fs-extra"); var Path = require("path"); var nThen = require("nthen"); const ToPull = require('stream-to-pull-stream'); @@ -67,7 +68,7 @@ var closeChannel = function (env, channelName, cb) { } }; -var clearChannel = function (env, channelId, cb) { +var clearChannel = function (env, channelId, cb) { // FIXME deletion var path = mkPath(env, channelId); getMetadataAtPath(env, path, function (e, metadata) { if (e) { return cb(new Error(e)); } @@ -189,7 +190,7 @@ var checkPath = function (path, callback) { return; } // 511 -> octal 777 - Fs.mkdir(Path.dirname(path), 511, function (err) { + Fse.mkdirp(Path.dirname(path), 511, function (err) { if (err && err.code !== 'EEXIST') { callback(err); return; @@ -199,7 +200,7 @@ var checkPath = function (path, callback) { }); }; -var removeChannel = function (env, channelName, cb) { +var removeChannel = function (env, channelName, cb) { // FIXME deletion var filename = mkPath(env, channelName); Fs.unlink(filename, cb); }; @@ -420,7 +421,7 @@ module.exports.create = function ( }; // 0x1ff -> 777 var it; - Fs.mkdir(env.root, 0x1ff, function (err) { + Fse.mkdirp(env.root, 0x1ff, function (err) { if (err && err.code !== 'EEXIST') { // TODO: somehow return a nice error throw err; diff --git a/storage/tasks.js b/storage/tasks.js index 85df70a8d..5a999998c 100644 --- a/storage/tasks.js +++ b/storage/tasks.js @@ -1,4 +1,5 @@ var Fs = require("fs"); +var Fse = require("fs-extra"); var Path = require("path"); var nacl = require("tweetnacl"); var nThen = require("nthen"); @@ -58,8 +59,8 @@ var write = function (env, task, cb) { var dir = id.slice(0, 2); var dirpath = Path.join(env.root, dir); - Fs.mkdir(dirpath, 0x1ff, w(function (err) { - if (err && err.code !== 'EEXIST') { + Fse.mkdirp(dirpath, 0x1ff, w(function (err) { + if (err) { return void cb(err); } })); @@ -72,13 +73,17 @@ var write = function (env, task, cb) { }); }; +// TODO implement a standard API for removing tasks +// currently they are deleted manually in 'expire-channels.js' +// var remove = function (env, id, cb) { }; + Tasks.create = function (config, cb) { var env = { root: config.taskPath || './tasks', }; // make sure the path exists... - Fs.mkdir(env.root, 0x1ff, function (err) { + Fse.mkdirp(env.root, 0x1ff, function (err) { if (err && err.code !== 'EEXIST') { throw err; } @@ -91,4 +96,3 @@ Tasks.create = function (config, cb) { }); }; -