修复 缺失的深层持久化读取

This commit is contained in:
Suwings 2022-02-17 22:45:58 +08:00
parent c50429310e
commit 62b5b3c6a9
2 changed files with 39 additions and 21 deletions

View File

@ -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);
}
/**

View File

@ -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}`);
}
// 内存限制