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 {
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
140156function 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- }
You can’t perform that action at this time.
0 commit comments