@@ -16,17 +16,6 @@ import logger from "./log";
1616import InstanceControl from "./system_instance_control" ;
1717import takeoverContainer from "./takeover_container" ;
1818
19- // init instance default install path
20- globalConfiguration . load ( ) ;
21- let INSTANCE_DATA_DIR = path . join ( process . cwd ( ) , "data/InstanceData" ) ;
22- if ( globalConfiguration . config . defaultInstancePath ) {
23- INSTANCE_DATA_DIR = path . normalize ( globalConfiguration . config . defaultInstancePath ) ;
24- }
25-
26- if ( ! fs . existsSync ( INSTANCE_DATA_DIR ) ) {
27- fs . mkdirsSync ( INSTANCE_DATA_DIR ) ;
28- }
29-
3019class InstanceSubsystem extends EventEmitter {
3120 public readonly GLOBAL_INSTANCE = "__MCSM_GLOBAL_INSTANCE__" ;
3221 public readonly GLOBAL_INSTANCE_UUID = "global0001" ;
@@ -35,9 +24,22 @@ class InstanceSubsystem extends EventEmitter {
3524
3625 public readonly instances = new Map < string , Instance > ( ) ;
3726 public readonly instanceStream = new InstanceStreamListener ( ) ;
27+ private instanceDataDir = "" ;
3828
3929 constructor ( ) {
4030 super ( ) ;
31+ // init instance default install path
32+ globalConfiguration . load ( ) ;
33+ let instanceDataDir = path . join ( process . cwd ( ) , "data/InstanceData" ) ;
34+ if ( globalConfiguration . config . defaultInstancePath ) {
35+ instanceDataDir = path . normalize ( globalConfiguration . config . defaultInstancePath ) ;
36+ }
37+ if ( ! fs . existsSync ( instanceDataDir ) ) fs . mkdirsSync ( instanceDataDir ) ;
38+ this . instanceDataDir = path . normalize ( instanceDataDir ) ;
39+ }
40+
41+ public getInstanceDataDir ( ) {
42+ return this . instanceDataDir ;
4143 }
4244
4345 // start automatically at boot
@@ -153,7 +155,7 @@ class InstanceSubsystem extends EventEmitter {
153155 const instance = new Instance ( newUuid , new InstanceConfig ( ) ) ;
154156 // Instance working directory verification and automatic creation
155157 if ( ! cfg . cwd || cfg . cwd === "." ) {
156- cfg . cwd = path . normalize ( `${ INSTANCE_DATA_DIR } /${ instance . instanceUuid } ` ) ;
158+ cfg . cwd = path . normalize ( `${ this . instanceDataDir } /${ instance . instanceUuid } ` ) ;
157159 }
158160 if ( ! fs . existsSync ( cfg . cwd ) ) fs . mkdirsSync ( cfg . cwd ) ;
159161 // Set the default input and output encoding
0 commit comments