@expiren/opencode-antigravity-auth 1.6.4 → 1.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +36 -22
- package/dist/index.js.map +2 -2
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js +50 -29
- package/dist/src/plugin/storage.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -671,6 +671,40 @@ async function loadAccounts() {
|
|
|
671
671
|
return null;
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
|
+
async function atomicWriteFile(targetPath, content) {
|
|
675
|
+
const tempPath = `${targetPath}.${randomBytes(6).toString("hex")}.tmp`;
|
|
676
|
+
await fs.writeFile(tempPath, content, { encoding: "utf-8", mode: 384 });
|
|
677
|
+
const RETRY_DELAYS = [50, 100, 200];
|
|
678
|
+
let lastError;
|
|
679
|
+
for (let attempt = 0; attempt <= RETRY_DELAYS.length; attempt++) {
|
|
680
|
+
try {
|
|
681
|
+
await fs.rename(tempPath, targetPath);
|
|
682
|
+
return;
|
|
683
|
+
} catch (error) {
|
|
684
|
+
lastError = error;
|
|
685
|
+
const code = error.code;
|
|
686
|
+
if (code !== "EPERM" && code !== "EACCES") {
|
|
687
|
+
break;
|
|
688
|
+
}
|
|
689
|
+
if (attempt < RETRY_DELAYS.length) {
|
|
690
|
+
await new Promise((r) => setTimeout(r, RETRY_DELAYS[attempt]));
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
try {
|
|
695
|
+
await fs.copyFile(tempPath, targetPath);
|
|
696
|
+
try {
|
|
697
|
+
await fs.unlink(tempPath);
|
|
698
|
+
} catch {
|
|
699
|
+
}
|
|
700
|
+
} catch {
|
|
701
|
+
try {
|
|
702
|
+
await fs.unlink(tempPath);
|
|
703
|
+
} catch {
|
|
704
|
+
}
|
|
705
|
+
throw lastError;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
674
708
|
async function saveAccounts(storage) {
|
|
675
709
|
const path5 = getStoragePath();
|
|
676
710
|
const configDir = dirname(path5);
|
|
@@ -679,18 +713,8 @@ async function saveAccounts(storage) {
|
|
|
679
713
|
await withFileLock(path5, async () => {
|
|
680
714
|
const existing = await loadAccountsUnsafe();
|
|
681
715
|
const merged = existing ? mergeAccountStorage(existing, storage) : storage;
|
|
682
|
-
const tempPath = `${path5}.${randomBytes(6).toString("hex")}.tmp`;
|
|
683
716
|
const content = JSON.stringify(merged, null, 2);
|
|
684
|
-
|
|
685
|
-
await fs.writeFile(tempPath, content, { encoding: "utf-8", mode: 384 });
|
|
686
|
-
await fs.rename(tempPath, path5);
|
|
687
|
-
} catch (error) {
|
|
688
|
-
try {
|
|
689
|
-
await fs.unlink(tempPath);
|
|
690
|
-
} catch {
|
|
691
|
-
}
|
|
692
|
-
throw error;
|
|
693
|
-
}
|
|
717
|
+
await atomicWriteFile(path5, content);
|
|
694
718
|
});
|
|
695
719
|
}
|
|
696
720
|
async function saveAccountsReplace(storage) {
|
|
@@ -699,18 +723,8 @@ async function saveAccountsReplace(storage) {
|
|
|
699
723
|
await fs.mkdir(configDir, { recursive: true });
|
|
700
724
|
await ensureGitignore(configDir);
|
|
701
725
|
await withFileLock(path5, async () => {
|
|
702
|
-
const tempPath = `${path5}.${randomBytes(6).toString("hex")}.tmp`;
|
|
703
726
|
const content = JSON.stringify(storage, null, 2);
|
|
704
|
-
|
|
705
|
-
await fs.writeFile(tempPath, content, { encoding: "utf-8", mode: 384 });
|
|
706
|
-
await fs.rename(tempPath, path5);
|
|
707
|
-
} catch (error) {
|
|
708
|
-
try {
|
|
709
|
-
await fs.unlink(tempPath);
|
|
710
|
-
} catch {
|
|
711
|
-
}
|
|
712
|
-
throw error;
|
|
713
|
-
}
|
|
727
|
+
await atomicWriteFile(path5, content);
|
|
714
728
|
});
|
|
715
729
|
}
|
|
716
730
|
async function loadAccountsUnsafe() {
|