diff --git a/src/common/system_storage.ts b/src/common/system_storage.ts index 1a5c394..7f32da9 100644 --- a/src/common/system_storage.ts +++ b/src/common/system_storage.ts @@ -41,6 +41,25 @@ class StorageSubsystem { fs.writeFileSync(filePath, data, { encoding: "utf-8" }); } + // 以复制目标方为原型的基本类型的深复制 + // target 复制目标 object 复制源 + protected defineAttr(target: any, object: any): any { + for (const v of Object.keys(target)) { + const objectValue = object[v]; + if (objectValue === undefined) continue; + if (objectValue instanceof Array) { + target[v] = objectValue; + continue; + } + if (objectValue instanceof Object && typeof objectValue === "object") { + this.defineAttr(target[v], objectValue); + continue; + } + target[v] = objectValue; + } + return target; + } + /** * 根据类定义和标识符实例化成对象 */ @@ -52,10 +71,11 @@ class StorageSubsystem { const data = fs.readFileSync(filePath, { encoding: "utf-8" }); const dataObject = JSON.parse(data); const target = new classz(); - for (const v of Object.keys(target)) { - if (dataObject[v] !== undefined) target[v] = dataObject[v]; - } - return target; + // for (const v of Object.keys(target)) { + // if (dataObject[v] !== undefined) target[v] = dataObject[v]; + // } + // 深层对象复制 + return this.defineAttr(target, dataObject); } /** diff --git a/src/entity/commands/docker/docker _start.ts b/src/entity/commands/docker/docker _start.ts index d51ae8a..ea1b5bb 100644 --- a/src/entity/commands/docker/docker _start.ts +++ b/src/entity/commands/docker/docker _start.ts @@ -142,25 +142,23 @@ export default class DockerStartCommand extends InstanceCommand { // 解析额外路径挂载 const extraVolumes = instance.config.docker.extraVolumes; const extraBinds = []; - if (extraVolumes) { - for (let it of extraVolumes) { - if (!it) continue; - const element = it.split(":"); - if (element.length != 2) continue; - let [hostPath, containerPath] = element; + for (const it of extraVolumes) { + if (!it) continue; + const element = it.split(":"); + if (element.length != 2) continue; + let [hostPath, containerPath] = element; - if (path.isAbsolute(containerPath)) { - containerPath = path.normalize(containerPath); - } else { - containerPath = path.normalize(path.join("/workspace/", containerPath)); - } - if (path.isAbsolute(hostPath)) { - hostPath = path.normalize(hostPath); - } else { - hostPath = path.normalize(path.join(process.cwd(), hostPath)); - } - extraBinds.push(`${hostPath}:${containerPath}`); + if (path.isAbsolute(containerPath)) { + containerPath = path.normalize(containerPath); + } else { + containerPath = path.normalize(path.join("/workspace/", containerPath)); } + if (path.isAbsolute(hostPath)) { + hostPath = path.normalize(hostPath); + } else { + hostPath = path.normalize(path.join(process.cwd(), hostPath)); + } + extraBinds.push(`${hostPath}:${containerPath}`); } // 内存限制