mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:40:44 +00:00
fix(plugins): harden install ledger path handling
This commit is contained in:
@@ -74,16 +74,30 @@ const config = fs.existsSync(configPath)
|
||||
const plugins = (config.plugins ??= {});
|
||||
const entries = (plugins.entries ??= {});
|
||||
entries[pluginId] = { ...(entries[pluginId] ?? {}), enabled };
|
||||
const installs = (plugins.installs ??= {});
|
||||
installs[pluginId] = {
|
||||
...(installs[pluginId] ?? {}),
|
||||
delete plugins.installs;
|
||||
plugins.allow = Array.from(new Set([...(plugins.allow ?? []), pluginId])).sort();
|
||||
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
||||
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
||||
|
||||
const ledgerPath = path.join(process.env.HOME, ".openclaw", "plugins", "installs.json");
|
||||
const ledger = fs.existsSync(ledgerPath)
|
||||
? JSON.parse(fs.readFileSync(ledgerPath, "utf8"))
|
||||
: {
|
||||
version: 1,
|
||||
warning:
|
||||
"DO NOT EDIT. This file is generated by OpenClaw plugin install/update/uninstall commands. Use `openclaw plugins install/update/uninstall` instead.",
|
||||
records: {},
|
||||
};
|
||||
ledger.updatedAtMs = Date.now();
|
||||
ledger.records ??= {};
|
||||
ledger.records[pluginId] = {
|
||||
...(ledger.records[pluginId] ?? {}),
|
||||
source: "path",
|
||||
installPath: pluginRoot,
|
||||
sourcePath: pluginRoot,
|
||||
};
|
||||
plugins.allow = Array.from(new Set([...(plugins.allow ?? []), pluginId])).sort();
|
||||
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
||||
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
||||
fs.mkdirSync(path.dirname(ledgerPath), { recursive: true });
|
||||
fs.writeFileSync(ledgerPath, `${JSON.stringify(ledger, null, 2)}\n`, "utf8");
|
||||
NODE
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user