forked from mirror/MCSM-Daemon
修复 缺失的深层持久化读取
This commit is contained in:
parent
c50429310e
commit
62b5b3c6a9
src
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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}`);
|
||||
}
|
||||
|
||||
// 内存限制
|
||||
|
Loading…
Reference in New Issue
Block a user