@@ -57,8 +57,6 @@ module.exports = class PromisifiedFS {
5757 this . backFile = this . _wrap ( this . backFile , cleanParamsFilepathOpts , true )
5858 this . du = this . _wrap ( this . du , cleanParamsFilepathOpts , false ) ;
5959
60- this . _backend = options . backend || new DefaultBackend ( ) ;
61-
6260 this . _deactivationPromise = null
6361 this . _deactivationTimeout = null
6462 this . _activationPromise = null
@@ -76,8 +74,15 @@ module.exports = class PromisifiedFS {
7674 }
7775 async _init ( name , options = { } ) {
7876 await this . _gracefulShutdown ( ) ;
77+ if ( this . _activationPromise ) await this . _deactivate ( )
7978
80- await this . _backend . init ( name , options ) ;
79+ if ( this . _backend && this . _backend . destroy ) {
80+ await this . _backend . destroy ( ) ;
81+ }
82+ this . _backend = options . backend || new DefaultBackend ( ) ;
83+ if ( this . _backend . init ) {
84+ await this . _backend . init ( name , options ) ;
85+ }
8186
8287 if ( this . _initPromiseResolve ) {
8388 this . _initPromiseResolve ( ) ;
@@ -130,12 +135,17 @@ module.exports = class PromisifiedFS {
130135 }
131136 if ( this . _deactivationPromise ) await this . _deactivationPromise
132137 this . _deactivationPromise = null
133- if ( ! this . _activationPromise ) this . _activationPromise = this . _backend . activate ( ) ;
138+ if ( ! this . _activationPromise ) {
139+ this . _activationPromise = this . _backend . activate ? this . _backend . activate ( ) : Promise . resolve ( ) ;
140+ }
134141 await this . _activationPromise
135142 }
136143 async _deactivate ( ) {
137144 if ( this . _activationPromise ) await this . _activationPromise
138- if ( ! this . _deactivationPromise ) this . _deactivationPromise = this . _backend . deactivate ( ) ;
145+
146+ if ( ! this . _deactivationPromise ) {
147+ this . _deactivationPromise = this . _backend . deactivate ? this . _backend . deactivate ( ) : Promise . resolve ( ) ;
148+ }
139149 this . _activationPromise = null
140150 if ( this . _gracefulShutdownResolve ) this . _gracefulShutdownResolve ( )
141151 return this . _deactivationPromise
0 commit comments