File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export class NodeFileStorage implements IStorage {
21
21
this . maxItems = maxItems ;
22
22
this . fs = fs ? fs : Fs ;
23
23
24
- mkdirParent ( this . directory ) ;
24
+ this . mkdir ( this . directory ) ;
25
25
this . index = this . createIndex ( this . directory ) ;
26
26
this . timestamp = this . index . length > 0
27
27
? this . index [ this . index . length - 1 ] . timestamp
@@ -135,6 +135,22 @@ export class NodeFileStorage implements IStorage {
135
135
} ;
136
136
} ) . sort ( ( a , b ) => a . timestamp - b . timestamp ) ;
137
137
}
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
+ } ;
138
154
}
139
155
140
156
function parseDate ( key , value ) {
@@ -148,13 +164,3 @@ function parseDate(key, value) {
148
164
return value ;
149
165
} ;
150
166
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
- }
You can’t perform that action at this time.
0 commit comments