mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:40:44 +00:00
fix: roll back plugin index on config write conflicts
This commit is contained in:
33
src/cli/plugins-install-record-commit.ts
Normal file
33
src/cli/plugins-install-record-commit.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { replaceConfigFile } from "../config/config.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import type { PluginInstallRecord } from "../config/types.plugins.js";
|
||||
import {
|
||||
PLUGIN_INSTALLS_CONFIG_PATH,
|
||||
writePersistedInstalledPluginIndexInstallRecords,
|
||||
} from "../plugins/installed-plugin-index-records.js";
|
||||
|
||||
export async function commitPluginInstallRecordsWithConfig(params: {
|
||||
previousInstallRecords: Record<string, PluginInstallRecord>;
|
||||
nextInstallRecords: Record<string, PluginInstallRecord>;
|
||||
nextConfig: OpenClawConfig;
|
||||
baseHash?: string;
|
||||
}): Promise<void> {
|
||||
await writePersistedInstalledPluginIndexInstallRecords(params.nextInstallRecords);
|
||||
try {
|
||||
await replaceConfigFile({
|
||||
nextConfig: params.nextConfig,
|
||||
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
|
||||
writeOptions: { unsetPaths: [Array.from(PLUGIN_INSTALLS_CONFIG_PATH)] },
|
||||
});
|
||||
} catch (error) {
|
||||
try {
|
||||
await writePersistedInstalledPluginIndexInstallRecords(params.previousInstallRecords);
|
||||
} catch (rollbackError) {
|
||||
throw new Error(
|
||||
"Failed to commit plugin install records and could not restore the previous plugin index",
|
||||
{ cause: rollbackError },
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user