Skip to content

Commit

Permalink
Use common.mkdirp instead of lib/utils.js#mkdirp
Browse files Browse the repository at this point in the history
PR-URL: #11
  • Loading branch information
SemenchenkoVitaliy authored and lundibundi committed May 8, 2019
1 parent 8150450 commit 8ea0e2c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/filestorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FileStorage {
// Throws: <TypeError>, 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;
Expand Down Expand Up @@ -143,7 +143,7 @@ class FileStorage {
// err - <Error>
// storage - <FileStorage>
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));
});
Expand Down
14 changes: 0 additions & 14 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -133,7 +120,6 @@ module.exports = {
getFilepath,
computeHash,
getDataStats,
mkdirp,
rmdirp,
compress,
uncompress,
Expand Down
3 changes: 2 additions & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 8ea0e2c

Please sign in to comment.