Skip to content

Commit a140b0f

Browse files
authored
Merge pull request #1889 from MCSManager/yumao/fix-bug-1126
fix: #1883
2 parents 744f07c + 3919f6a commit a140b0f

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

daemon/src/service/docker_process_service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { IInstanceProcess } from "../entity/instance/interface";
1414
import { $t } from "../i18n";
1515
import { AsyncTask } from "./async_task_service";
1616
import logger from "./log";
17+
import InstanceSubsystem from "./system_instance";
1718

1819
type PublicPortArray = {
1920
[key: string]: { HostPort: string }[];
@@ -152,8 +153,9 @@ export class SetupDockerContainer extends AsyncTask {
152153
const workingDir = dockerConfig.workingDir || undefined;
153154

154155
let cwd = instance.absoluteCwdPath();
156+
const defaultInstanceDir = InstanceSubsystem.getInstanceDataDir();
155157
const hostRealPath = toText(process.env.MCSM_DOCKER_WORKSPACE_PATH);
156-
if (hostRealPath) {
158+
if (hostRealPath && cwd.includes(defaultInstanceDir)) {
157159
cwd = path.normalize(path.join(hostRealPath, instance.instanceUuid));
158160
}
159161

daemon/src/service/system_instance.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ import logger from "./log";
1616
import InstanceControl from "./system_instance_control";
1717
import 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-
3019
class 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

Comments
 (0)