Snapshot only committed extensions and publish the last-good marker atomically
This commit is contained in:
@@ -30546,7 +30546,7 @@ async function loadExtensions(harness2, registry2, storage2, models2, context, b
|
||||
const loaderGit = async (...args) => {
|
||||
for (let attempt = 0; ; attempt++) {
|
||||
try {
|
||||
const result = await exec(["git", ...args], { cwd: repo, timeout: 120, signal: commands.signal });
|
||||
const result = await exec(["git", ...args], { cwd: repo, signal: commands.signal });
|
||||
if (result.code) throw new Error(result.stderr || `git exited ${result.code}`);
|
||||
return result.stdout.trim();
|
||||
} catch (error) {
|
||||
@@ -30562,7 +30562,8 @@ async function loadExtensions(harness2, registry2, storage2, models2, context, b
|
||||
const publish2 = async () => {
|
||||
await harness2.commit(async (tx) => Object.assign(await tx.doc(ExtensionState), state), context);
|
||||
ops2.op_extension_status(JSON.stringify(state));
|
||||
await fs.write("/src/sausage/.git/sausage-last-good", state.good ?? "");
|
||||
await fs.write("/src/sausage/.git/sausage-last-good.tmp", state.good ?? "");
|
||||
await fs.rename("/src/sausage/.git/sausage-last-good.tmp", "/src/sausage/.git/sausage-last-good");
|
||||
};
|
||||
const dispose = async (entries2) => {
|
||||
for (const facet of entries2) for (const cleanup of facet.close) {
|
||||
@@ -30652,8 +30653,19 @@ async function loadExtensions(harness2, registry2, storage2, models2, context, b
|
||||
try {
|
||||
await fs.stat(snapshot);
|
||||
} catch {
|
||||
await loaderGit("worktree", "prune");
|
||||
await loaderGit("worktree", "add", "--detach", snapshot, sha);
|
||||
const staging = `${snapshot}.tmp`, archive = `${snapshot}.tar`;
|
||||
try {
|
||||
await fs.mkdir(staging);
|
||||
} catch (error) {
|
||||
if (error.code !== "already_exists") throw error;
|
||||
}
|
||||
if (await loaderGit("ls-tree", "--name-only", sha, "extensions")) {
|
||||
await loaderGit("archive", "--format=tar", `--output=${archive}`, sha, "extensions");
|
||||
const result = await exec(["tar", "-xf", archive, "-C", staging], { cwd: repo, signal: commands.signal });
|
||||
if (result.code) throw new Error(`tar: ${result.stderr || result.code}`);
|
||||
await fs.remove(archive);
|
||||
}
|
||||
await fs.rename(staging, snapshot);
|
||||
}
|
||||
const modules = [];
|
||||
for (const entry2 of await fs.list(`${snapshot}/extensions`).catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user