Skip to content

Commit 9f8fc56

Browse files
committed
Fix in NodeFileStorage: mkdir
1 parent 7b1c26f commit 9f8fc56

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/storage/NodeFileStorage.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class NodeFileStorage implements IStorage {
2121
this.maxItems = maxItems;
2222
this.fs = fs ? fs : Fs;
2323

24-
mkdirParent(this.directory);
24+
this.mkdir(this.directory);
2525
this.index = this.createIndex(this.directory);
2626
this.timestamp = this.index.length > 0
2727
? this.index[this.index.length - 1].timestamp
@@ -135,6 +135,22 @@ export class NodeFileStorage implements IStorage {
135135
};
136136
}).sort((a, b) => a.timestamp - b.timestamp);
137137
}
138+
139+
private mkdir(path) {
140+
let dirs = path.split(Path.sep);
141+
let root = '';
142+
143+
while (dirs.length > 0) {
144+
let dir = dirs.shift();
145+
if (dir === '') {
146+
root = Path.sep;
147+
}
148+
if (!this.fs.existsSync(root + dir)) {
149+
this.fs.mkdirSync(root + dir);
150+
}
151+
root += dir + Path.sep;
152+
}
153+
};
138154
}
139155

140156
function parseDate(key, value) {
@@ -148,13 +164,3 @@ function parseDate(key, value) {
148164
return value;
149165
};
150166

151-
function mkdirParent(dirPath) {
152-
try {
153-
this.fs.mkdirSync(dirPath);
154-
} catch (e) {
155-
if (e.errno === 34) {
156-
mkdirParent(Path.dirname(dirPath));
157-
mkdirParent(dirPath);
158-
}
159-
}
160-
}

0 commit comments

Comments
 (0)