From 8ea0e2cbc60ba2be9cb4e7dcbe2d608f29405a61 Mon Sep 17 00:00:00 2001 From: Vitaliy Semenchenko Date: Tue, 7 May 2019 16:20:04 +0300 Subject: [PATCH] Use common.mkdirp instead of lib/utils.js#mkdirp PR-URL: https://github.com/metarhia/filestorage/pull/11 --- lib/filestorage.js | 4 ++-- lib/utils.js | 14 -------------- test/utils.js | 3 ++- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/lib/filestorage.js b/lib/filestorage.js index cfb3205..e8960a7 100644 --- a/lib/filestorage.js +++ b/lib/filestorage.js @@ -36,7 +36,7 @@ class FileStorage { // Throws: , if `opts.checksum` or `opts.dedupHash` is incorrect write(id, data, opts, cb) { const file = this[getFilepath](id); - utils.mkdirp(path.dirname(file), err => { + common.mkdirp(path.dirname(file), err => { if (err) { cb(err); return; @@ -143,7 +143,7 @@ class FileStorage { // err - // storage - const create = (options, cb) => { - utils.mkdirp(path.resolve(options.dir), err => { + common.mkdirp(path.resolve(options.dir), err => { if (err) cb(err); else cb(null, new FileStorage(options)); }); diff --git a/lib/utils.js b/lib/utils.js index 4d18ba5..15eac1c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -28,19 +28,6 @@ const FS_EXT = 'f'; const getFilepath = (...parts) => `${path.join(...parts)}.${FS_EXT}`; -const mkdirp = (dir, cb) => { - fs.access(dir, fs.constants.F_OK, err => { - if (err && err.code === 'ENOENT') { - mkdirp(path.dirname(dir), err => { - if (err) cb(err); - else fs.mkdir(dir, cb); - }); - } else { - cb(err); - } - }); -}; - const rmdirp = (dir, cb) => { fs.stat(dir, (err, stats) => { if (err) { @@ -133,7 +120,6 @@ module.exports = { getFilepath, computeHash, getDataStats, - mkdirp, rmdirp, compress, uncompress, diff --git a/test/utils.js b/test/utils.js index ffaad71..9bd6f44 100644 --- a/test/utils.js +++ b/test/utils.js @@ -4,6 +4,7 @@ const fs = require('fs'); const path = require('path'); const utils = require('../lib/utils'); const metatests = require('metatests'); +const common = require('@metarhia/common'); const testDir = path.join(__dirname, 'utils-test-root'); @@ -77,7 +78,7 @@ const finish = test => { metatests.test('', test => { const dir = path.join(testDir, 'some', 'path', 'to', 'nested', 'dir'); - utils.mkdirp(dir, err => { + common.mkdirp(dir, err => { test.error(err); test.strictSame(fs.existsSync(dir), true);