Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 62b5b3c

Browse files
committed
修复 缺失的深层持久化读取
1 parent c504293 commit 62b5b3c

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

src/common/system_storage.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ class StorageSubsystem {
4141
fs.writeFileSync(filePath, data, { encoding: "utf-8" });
4242
}
4343

44+
// 以复制目标方为原型的基本类型的深复制
45+
// target 复制目标 object 复制源
46+
protected defineAttr(target: any, object: any): any {
47+
for (const v of Object.keys(target)) {
48+
const objectValue = object[v];
49+
if (objectValue === undefined) continue;
50+
if (objectValue instanceof Array) {
51+
target[v] = objectValue;
52+
continue;
53+
}
54+
if (objectValue instanceof Object && typeof objectValue === "object") {
55+
this.defineAttr(target[v], objectValue);
56+
continue;
57+
}
58+
target[v] = objectValue;
59+
}
60+
return target;
61+
}
62+
4463
/**
4564
* 根据类定义和标识符实例化成对象
4665
*/
@@ -52,10 +71,11 @@ class StorageSubsystem {
5271
const data = fs.readFileSync(filePath, { encoding: "utf-8" });
5372
const dataObject = JSON.parse(data);
5473
const target = new classz();
55-
for (const v of Object.keys(target)) {
56-
if (dataObject[v] !== undefined) target[v] = dataObject[v];
57-
}
58-
return target;
74+
// for (const v of Object.keys(target)) {
75+
// if (dataObject[v] !== undefined) target[v] = dataObject[v];
76+
// }
77+
// 深层对象复制
78+
return this.defineAttr(target, dataObject);
5979
}
6080

6181
/**

src/entity/commands/docker/docker _start.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,23 @@ export default class DockerStartCommand extends InstanceCommand {
142142
// 解析额外路径挂载
143143
const extraVolumes = instance.config.docker.extraVolumes;
144144
const extraBinds = [];
145-
if (extraVolumes) {
146-
for (let it of extraVolumes) {
147-
if (!it) continue;
148-
const element = it.split(":");
149-
if (element.length != 2) continue;
150-
let [hostPath, containerPath] = element;
151-
152-
if (path.isAbsolute(containerPath)) {
153-
containerPath = path.normalize(containerPath);
154-
} else {
155-
containerPath = path.normalize(path.join("/workspace/", containerPath));
156-
}
157-
if (path.isAbsolute(hostPath)) {
158-
hostPath = path.normalize(hostPath);
159-
} else {
160-
hostPath = path.normalize(path.join(process.cwd(), hostPath));
161-
}
162-
extraBinds.push(`${hostPath}:${containerPath}`);
145+
for (const it of extraVolumes) {
146+
if (!it) continue;
147+
const element = it.split(":");
148+
if (element.length != 2) continue;
149+
let [hostPath, containerPath] = element;
150+
151+
if (path.isAbsolute(containerPath)) {
152+
containerPath = path.normalize(containerPath);
153+
} else {
154+
containerPath = path.normalize(path.join("/workspace/", containerPath));
155+
}
156+
if (path.isAbsolute(hostPath)) {
157+
hostPath = path.normalize(hostPath);
158+
} else {
159+
hostPath = path.normalize(path.join(process.cwd(), hostPath));
163160
}
161+
extraBinds.push(`${hostPath}:${containerPath}`);
164162
}
165163

166164
// 内存限制

0 commit comments

Comments
 (0)