@cortexkit/opencode-openai-auth 1.8.1 → 1.8.2

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.
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";
2
+ import { lstat, mkdir, open, readFile, rename, rm, stat, } from "node:fs/promises";
3
3
  import { dirname, join } from "node:path";
4
4
  import { createPrivateBytes, createPrivateDirectoryExclusive, ensurePrivateDirectory, PrivateFileError, privateOperation, readPrivateText, verifyPrivate, windowsPrivateFiles, writePrivateAtomic, } from "./375d9cca2def037d-private-files.js";
5
5
  import { LockOwnershipError, lockPathFor } from "./4825e03209d6ae3e-with-lock.js";
@@ -13,9 +13,35 @@ import { LockOwnershipError, lockPathFor } from "./4825e03209d6ae3e-with-lock.js
13
13
  */
14
14
  async function createExclusiveText(path, text) {
15
15
  const handle = await open(path, 'wx', 0o600);
16
+ let createdStat;
17
+ try {
18
+ createdStat = await handle.stat();
19
+ }
20
+ catch {
21
+ createdStat = undefined;
22
+ }
16
23
  try {
17
24
  await handle.writeFile(text, 'utf8');
18
25
  }
26
+ catch (error) {
27
+ // A failed write after an exclusive create leaves a partial file behind.
28
+ // Remove only the file just created: when a contender has meanwhile
29
+ // replaced the path, the identities differ and the successor is left
30
+ // alone. Removal failures must never mask the original write error.
31
+ try {
32
+ const current = await lstat(path).catch(() => undefined);
33
+ if (createdStat &&
34
+ current &&
35
+ current.dev === createdStat.dev &&
36
+ current.ino === createdStat.ino) {
37
+ await rm(path, { force: true }).catch(() => { });
38
+ }
39
+ }
40
+ catch {
41
+ // Best effort only; the original error below explains the failure.
42
+ }
43
+ throw error;
44
+ }
19
45
  finally {
20
46
  await handle.close();
21
47
  }
@@ -31,6 +57,31 @@ export function isLostMarkerRaceError(error) {
31
57
  return (code === 'ENOENT' ||
32
58
  (!windowsPrivateFiles && (code === 'EINVAL' || code === 'ENOTDIR')));
33
59
  }
60
+ let evictionMarkerTestHooks;
61
+ /**
62
+ * Tests only: inject a failure or a directory replacement between the
63
+ * eviction-marker mkdir and its owner.json write. Production never sets this.
64
+ * Not exported from the fs entry point, so it is not part of the public API.
65
+ */
66
+ export function setEvictionMarkerTestHooksForTest(hooks) {
67
+ evictionMarkerTestHooks = hooks;
68
+ }
69
+ function sameMarkerDirectory(created, current) {
70
+ if (created.dev !== current.dev || created.ino !== current.ino)
71
+ return false;
72
+ // Windows reports the directory identity as a file id that can be 0; fall
73
+ // back to creation time so a reused id does not look like the same directory.
74
+ if (created.ino === 0 && created.birthtimeMs !== current.birthtimeMs)
75
+ return false;
76
+ return true;
77
+ }
78
+ /**
79
+ * An ownerless marker older than this is recoverable without waiting for the
80
+ * full eviction TTL. Honest holders write owner.json within tens of
81
+ * milliseconds of the mkdir, so one second leaves wide margin for slow Windows
82
+ * filesystems while still bounding the stall from a crashed holder.
83
+ */
84
+ const OWNERLESS_MARKER_GRACE_MS = 1_000;
34
85
  /** Filesystem leases share wall time across all callers and processes. */
35
86
  export function acquireRefreshFileLock(options) {
36
87
  return acquireRefreshFileLockWithClock({ ...options, now: Date.now });
@@ -321,12 +372,66 @@ export async function acquireRefreshFileLockWithClock(options) {
321
372
  await removeLeaseObject(evictPath);
322
373
  }
323
374
  }
375
+ // Returns whether the directory at the marker path was still the one this
376
+ // process created when its owner write failed. Only then is the failure ours
377
+ // to report: a gone or replaced directory is a lost race.
378
+ async function removeOwnMarkerAfterFailedOwnerWrite(created) {
379
+ // Best effort only: never throws, so the original owner-write error below
380
+ // keeps explaining the failure. Removes the directory this process just
381
+ // created when its owner write failed, and leaves a contender's
382
+ // replacement alone when the identities differ.
383
+ if (!created)
384
+ return false;
385
+ let current;
386
+ try {
387
+ const st = await lstat(evictPath);
388
+ current = { dev: st.dev, ino: st.ino, birthtimeMs: st.birthtimeMs };
389
+ }
390
+ catch {
391
+ // Renamed away by a contender's steal: nothing of ours left to clean.
392
+ return false;
393
+ }
394
+ if (!sameMarkerDirectory(created, current))
395
+ return false;
396
+ // Remove only an ownerless directory. An owner file that appeared after
397
+ // our failed write belongs to someone: ours goes through
398
+ // releaseEvictionMarker in the caller, and a contender's must stay, since
399
+ // it may be holding the marker right now.
400
+ try {
401
+ await stat(evictOwnerPath);
402
+ return true;
403
+ }
404
+ catch (error) {
405
+ if (error.code !== 'ENOENT')
406
+ return true;
407
+ }
408
+ try {
409
+ await removeLeaseObject(evictPath);
410
+ }
411
+ catch {
412
+ // A removal failure keeps the stale marker recoverable later; it must
413
+ // never mask the original owner-write error.
414
+ }
415
+ return true;
416
+ }
324
417
  async function tryAcquireEvictionMarker() {
325
418
  if (windowsPrivateFiles)
326
419
  await createPrivateDirectoryExclusive(evictPath);
327
420
  else
328
421
  await mkdir(evictPath);
422
+ let created;
329
423
  try {
424
+ const st = await lstat(evictPath);
425
+ created = { dev: st.dev, ino: st.ino, birthtimeMs: st.birthtimeMs };
426
+ }
427
+ catch {
428
+ created = undefined;
429
+ }
430
+ try {
431
+ await evictionMarkerTestHooks?.beforeOwnerWrite?.(evictPath, evictOwnerPath);
432
+ const injected = await evictionMarkerTestHooks?.failOwnerWrite?.(evictPath, evictOwnerPath);
433
+ if (injected !== undefined)
434
+ throw injected;
330
435
  const bytes = `${JSON.stringify({ ownerId: evictOwnerId, createdAt: now() })}\n`;
331
436
  if (windowsPrivateFiles)
332
437
  await createPrivateBytes(evictOwnerPath, bytes);
@@ -339,9 +444,26 @@ export async function acquireRefreshFileLockWithClock(options) {
339
444
  // path below does exactly that). That is a lost race, not a failure, so
340
445
  // report it as such and let the caller back off and retry rather than
341
446
  // failing the whole lock acquisition.
342
- if (isLostMarkerRaceError(error))
447
+ //
448
+ // The race codes alone cannot prove the directory is gone: the same
449
+ // codes can surface while our directory is still in place (for example
450
+ // a permission failure while writing the owner file, which used to
451
+ // leave an ownerless marker behind). The identity fence
452
+ // above removes only the directory this process created, and is a no-op
453
+ // when the contender renamed it away or replaced it, so run it on both
454
+ // branches before deciding between a retry and a failure.
455
+ // A race code while our own directory is still in place is not a lost
456
+ // race but a write that fails here every time: report it, rather than
457
+ // retrying the same failure until a deadline hides the cause.
458
+ const stillOurs = await removeOwnMarkerAfterFailedOwnerWrite(created);
459
+ if (isLostMarkerRaceError(error) && !stillOurs)
343
460
  return false;
344
- await releaseEvictionMarker();
461
+ try {
462
+ await releaseEvictionMarker();
463
+ }
464
+ catch {
465
+ // Removal must never mask the original owner-write error.
466
+ }
345
467
  throw error;
346
468
  }
347
469
  if (options.onStep)
@@ -358,10 +480,42 @@ export async function acquireRefreshFileLockWithClock(options) {
358
480
  return 'missing';
359
481
  throw error;
360
482
  }
361
- if (windowsPrivateFiles)
362
- await verifyPrivate(evictPath, 'directory', true);
363
- if (evictStat.mtimeMs + EVICT_TTL > now())
364
- return 'fresh';
483
+ if (windowsPrivateFiles) {
484
+ try {
485
+ await verifyPrivate(evictPath, 'directory', true);
486
+ }
487
+ catch (error) {
488
+ // The marker's holder can remove it between the stat above and this
489
+ // check. Absence means the marker is free, as when the stat finds
490
+ // nothing; every other refusal still escapes.
491
+ if (error.code === 'ENOENT')
492
+ return 'missing';
493
+ throw error;
494
+ }
495
+ }
496
+ if (evictStat.mtimeMs + EVICT_TTL > now()) {
497
+ // A fresh marker with no owner is either this process's orphan (its
498
+ // owner write just failed) or a holder that crashed between mkdir and
499
+ // owner write. Honest holders publish owner.json within tens of
500
+ // milliseconds, so recover ownerless markers after a short grace instead
501
+ // of stalling for the full TTL. Stealing one is safe: a live holder
502
+ // stalled past the grace sees its pending owner write fail with ENOENT
503
+ // (a lost race) and retries, rather than acting on a stolen marker.
504
+ let hasOwner = true;
505
+ try {
506
+ await stat(evictOwnerPath);
507
+ }
508
+ catch (error) {
509
+ if (error.code === 'ENOENT')
510
+ hasOwner = false;
511
+ else
512
+ return 'fresh';
513
+ }
514
+ if (hasOwner)
515
+ return 'fresh';
516
+ if (evictStat.mtimeMs + OWNERLESS_MARKER_GRACE_MS > now())
517
+ return 'fresh';
518
+ }
365
519
  if (options.onStep)
366
520
  await options.onStep('stale-marker-stat');
367
521
  const claimedPath = `${evictPath}.${randomUUID()}`;
@@ -386,11 +540,13 @@ export async function acquireRefreshFileLockWithClock(options) {
386
540
  catch (error) {
387
541
  if (error.code === 'EEXIST') {
388
542
  if (windowsPrivateFiles) {
389
- await verifyPrivate(evictPath, 'directory', true);
390
543
  try {
544
+ await verifyPrivate(evictPath, 'directory', true);
391
545
  await readPrivateText(evictOwnerPath, true);
392
546
  }
393
547
  catch (ownerError) {
548
+ // A marker removed by its holder after the failed create is free:
549
+ // report it as unavailable for now so the caller retries.
394
550
  if (ownerError.code !== 'ENOENT')
395
551
  throw ownerError;
396
552
  }
@@ -686,7 +842,12 @@ export async function acquireRefreshFileLockWithClock(options) {
686
842
  released = true;
687
843
  cancelRenewalTimer();
688
844
  await renewalInFlight;
689
- for (let attempt = 0; attempt < MAX_STEAL_ATTEMPTS; attempt++) {
845
+ // A fresh marker may outlive a few quick retries, especially on Windows.
846
+ // Allow its full TTL plus recovery time, using a monotonic deadline so
847
+ // wall-clock adjustments cannot extend the retry deadline.
848
+ const deadline = performance.now() + EVICT_TTL + 1_000;
849
+ let delayMs = 5;
850
+ for (;;) {
690
851
  try {
691
852
  let removalConfirmed = false;
692
853
  const markerAcquired = await withEvictionMarker(async () => {
@@ -728,7 +889,11 @@ export async function acquireRefreshFileLockWithClock(options) {
728
889
  throw error;
729
890
  return;
730
891
  }
731
- await backoff();
892
+ const remainingMs = deadline - performance.now();
893
+ if (remainingMs <= 0)
894
+ break;
895
+ await new Promise((resolve) => setTimeout(resolve, Math.min(delayMs, remainingMs)));
896
+ delayMs = Math.min(delayMs * 2, 50);
732
897
  }
733
898
  // Do not delete by pathname without the marker: bounded retries leave the
734
899
  // lease to expire rather than risking removal of a successor's lock.
@@ -1,8 +0,0 @@
1
- import{if as H,jf as q,kf as V0,mf as x,nf as h,of as S,pf as w,qf as _0,sf as b}from"./index-mg4w434p.js";import{randomUUID as T}from"node:crypto";import{mkdir as H0,open as B0,readFile as Q0,rename as W0,rm as L,stat as Y0}from"node:fs/promises";import{dirname as P,join as Z0}from"node:path";function N0($,G){return`${$}.${G}.lock`}class G0 extends Error{details;constructor($){super(`Timed out acquiring ${$.name} lock for ${$.target}`);this.name="LockContentionError",this.details=$}}class f extends Error{details;constructor($){super(`Lost ${$.name} lock for ${$.target}`);this.name="LockOwnershipError",this.details=$}}async function A0($,G,Q){let Y=performance.now();for(;;){G.signal?.throwIfAborted();let Z=await K0({path:$,name:G.name,ttlMs:G.ttlMs,renew:G.renew??!1,...G.onStep?{onStep:G.onStep}:{},...G.onRenewalTimer?{onRenewalTimer:G.onRenewalTimer}:{}});if(Z)try{return G.signal?.throwIfAborted(),await Q(Z)}finally{await Z.release()}let J=G.timeoutMs-(performance.now()-Y);if(J<=0)throw new G0({target:$,name:G.name,timeoutMs:G.timeoutMs});await new Promise((_)=>setTimeout(_,Math.min(25,Math.ceil(J))))}}async function J0($,G){let Q=await B0($,"wx",384);try{await Q.writeFile(G,"utf8")}finally{await Q.close()}}var D0=globalThis.setTimeout.bind(globalThis),U0=globalThis.clearTimeout.bind(globalThis);function q0($){let G=$?.code;return G==="ENOENT"||!H&&(G==="EINVAL"||G==="ENOTDIR")}function K0($){return x0({...$,now:Date.now})}async function x0($){let G=N0($.path,$.name),Q=Z0(G,"owner.json"),Y=T(),Z=$.now??Date.now,J=null,_=!1,D=!1,B,l,j0=new Promise((z)=>{l=z});function p(z){try{let K=$.onRenewalTimer?.(z);if(K&&(typeof K==="object"||typeof K==="function")&&"then"in K&&typeof K.then==="function")Promise.resolve(K).catch(()=>{})}catch{}}function d(){if(!J)return;U0(J),J=null,p("cancelled")}function g(z,K){if(B||_)return;B=Object.freeze({reason:z,expectedOwnerId:Y,...typeof K?.ownerId==="string"?{observedOwnerId:K.ownerId}:{},...typeof K?.expiresAt==="number"?{observedExpiresAt:K.expiresAt}:{}}),d(),l(B)}let E,R=null,C=`${G}.evicting`,M=Z0(C,"owner.json"),a=T(),g0=5000,y=8;async function j(){if(H)try{return JSON.parse(await S(G,!0))}catch(z){if(z.code!=="EISDIR"&&z.reason!=="wrong-kind")throw z;return await x(G,"directory",!0),JSON.parse(await S(Q,!0))}try{return JSON.parse(await Q0(G,"utf8"))}catch(z){if(z.code!=="EISDIR")throw z;return JSON.parse(await Q0(Q,"utf8"))}}async function C0(){if(H){let W=await j(),V=Number(W?.expiresAt)-Z();await b(G,`${JSON.stringify({ownerId:Y,expiresAt:Z()+$.ttlMs})}
2
- `,{deadline:performance.now()+Math.max(0,V),beforeRename:async()=>{let I=await j();if(I?.ownerId!==Y||!(Number(I?.expiresAt)>Z())||!await X())throw new f({target:$.path,name:$.name})}});return}let z=`${G}.${T()}.tmp`,K,N=!1;try{K=await B0(z,"wx",384),N=!0,await K.writeFile(`${JSON.stringify({ownerId:Y,expiresAt:Z()+$.ttlMs})}
3
- `,"utf8"),await K.chmod(384),await K.close(),K=void 0;let W=await j();if(W?.ownerId!==Y||!(Number(W?.expiresAt)>Z())||!await X())throw new f({target:$.path,name:$.name});await W0(z,G),N=!1}finally{if(await K?.close().catch(()=>{}),N)await L(z,{force:!0}).catch(()=>{})}}async function s(){let z=`${JSON.stringify({ownerId:Y,expiresAt:Z()+$.ttlMs})}
4
- `;if(H)await w(G,z);else await J0(G,z)}async function n(z){let K=z.code;if(K!=="EEXIST"&&K!=="EISDIR")return!1;if(H){if($.onStep)await $.onStep("lease-contention-read-ready");try{if(K==="EISDIR")await x(G,"directory",!0),await S(Q,!0);else await j()}catch(N){if(N.code!=="ENOENT")throw N}}return!0}async function k(){if(H)await h(P(G));try{return await s(),!0}catch(z){let K=z.code;if(await n(z))return!1;if(K==="ENOENT"){if(H)await h(P(G));else await H0(P(G),{recursive:!0});try{return await s(),!0}catch(N){if(await n(N))return!1;throw N}}throw z}}async function O(){await new Promise((z)=>setTimeout(z,Math.floor(Math.random()*4)))}async function m(z=!0){if(z&&$.onStep)await $.onStep("lock-read-ready");let K;try{K=await j()}catch(W){if(H&&W.code!=="ENOENT")throw W}let N=Number(K?.expiresAt);if(Number.isFinite(N)&&N>Z())return{status:"live"};if(typeof K?.ownerId==="string"&&Number.isFinite(N))return{status:"stale",identity:{kind:"owner",ownerId:K.ownerId,expiresAt:N}};try{let W=await Y0(G),V=Number.isFinite(N)?N:W.mtimeMs+$.ttlMs;if(V>Z())return{status:"live"};return{status:"stale",identity:{kind:"stat",dev:W.dev,ino:W.ino,mtimeMs:W.mtimeMs,expiresAt:V}}}catch(W){if(W.code==="ENOENT"){if($.onStep)await $.onStep("lock-missing");return{status:"missing"}}throw W}}function i(z,K){if(K.status!=="stale")return!1;let N=K.identity;if(z.kind==="owner"&&N.kind==="owner")return z.ownerId===N.ownerId&&z.expiresAt===N.expiresAt;return z.kind==="stat"&&N.kind==="stat"&&z.dev===N.dev&&z.ino===N.ino&&z.mtimeMs===N.mtimeMs&&z.expiresAt===N.expiresAt}async function X(){try{return JSON.parse(await S(M,H))?.ownerId===a}catch(z){if(H&&z.code!=="ENOENT")throw z;return!1}}async function A(z){if(H)await V0(z,"remove",()=>L(z,{recursive:!0,force:!0}));else await L(z,{recursive:!0,force:!0}).catch(()=>{})}async function u(){if(await X())await A(C)}async function t(){if(H)await _0(C);else await H0(C);try{let z=`${JSON.stringify({ownerId:a,createdAt:Z()})}
5
- `;if(H)await w(M,z);else await J0(M,z)}catch(z){if(q0(z))return!1;throw await u(),z}if($.onStep)await $.onStep("eviction-marker-acquired");return!0}async function r(){let z;try{z=await Y0(C)}catch(N){if(N.code==="ENOENT")return"missing";throw N}if(H)await x(C,"directory",!0);if(z.mtimeMs+g0>Z())return"fresh";if($.onStep)await $.onStep("stale-marker-stat");let K=`${C}.${T()}`;try{await W0(C,K)}catch(N){if(N.code==="ENOENT")return"missing";throw N}if($.onStep)await $.onStep("stale-marker-claimed");return await A(K),"recovered"}async function o(z){try{if(!await t())return!1}catch(K){if(K.code==="EEXIST"){if(H){await x(C,"directory",!0);try{await S(M,!0)}catch(N){if(N.code!=="ENOENT")throw N}}return!1}throw K}try{await z()}finally{await u()}return!0}async function e(){for(let z=0;z<y;z++){if($.onStep)await $.onStep("relinquish-read");let K;try{K=await j()}catch(N){if(H)throw N;return}if(K?.ownerId!==Y)return;try{await L(G,{recursive:!0,force:!0});return}catch(N){if(H)throw N;await O()}}}function $0(){if(!$.renew||_||B)return;let z=$.renewIntervalMs??Math.max(1000,Math.floor($.ttlMs/3));if(J=D0(()=>{J=null;let K=(async()=>{let N=!_;try{if(!await o(async()=>{let V=await j(),I=Z();if(_||B){N=!1;return}if(V?.ownerId!==Y){g("taken-over",V),N=!1;return}if(!(Number(V?.expiresAt)>I)){g("expired",V),N=!1;return}if($.onStep)await $.onStep("renewal-owner-confirmed");if(_||B){N=!1;return}if(!await X())return;if($.onStep)await $.onStep("renewal-write-fenced");if(_||B){N=!1;return}if(!await X())return;if($.onStep)await $.onStep("renewal-write-ready");if(_||B){N=!1;return}if(await C0(),$.onStep)await $.onStep("renewal-write-finished");if(!await X()){g("marker-lost"),N=!1,await e();return}})&&$.onStep)await $.onStep("renewal-marker-unavailable")}catch(W){if(H&&W instanceof q)E=W,g("renewal-failed"),N=!1;try{let V=await j();if(V?.ownerId!==Y)g("taken-over",V);else if(!(Number(V?.expiresAt)>Z()))g("expired",V)}catch{g("renewal-failed")}}finally{if($.onStep)try{await $.onStep("renewal-finished")}catch{}if(N&&!_&&!B)$0()}})();R=K,K.finally(()=>{if(R===K)R=null})},z),"unref"in J)J.unref();p("scheduled")}function z0(){try{let z=$.onContended?.();if(z&&(typeof z==="object"||typeof z==="function")&&"then"in z&&typeof z.then==="function")Promise.resolve(z).catch(()=>{})}catch{}return null}let U=await k();if(!U)for(let z=0;z<y;z++){if(U=await k(),U)break;let K=await m();if(K.status==="live")return z0();if(K.status==="missing")continue;if($.onStep)await $.onStep("stale-lock-observed");try{if(!await t()){await O();continue}}catch(N){if(N.code!=="EEXIST")throw N;if(await r()==="fresh")return null;await O();continue}try{let N=await m();if(N.status==="live")return z0();if(!i(K.identity,N))continue;if(!await X())return null;if($.onStep)await $.onStep("stale-lock-confirmed");if(!await X())return null;let W=await m(!1);if(!i(K.identity,W))continue;if(await A(G),!await X())return null;if($.onStep)await $.onStep("stale-lock-removed");if(U=await k(),!U)return null;if($.onStep)await $.onStep("stale-lock-recreated");if(!await X())return await e(),U=!1,null;break}finally{await u()}}if(!U)return null;return $0(),{ownerId:Y,whenLost:()=>j0,hasLost:()=>B!==void 0,assertOwned:async()=>{if(E)throw E;let z;try{let K=await j();if(z=K,!_&&!B&&K?.ownerId===Y&&Number(K?.expiresAt)>Z())return;g(K?.ownerId!==Y?"taken-over":"expired",K)}catch(K){if(g("unreadable"),H&&K instanceof q)throw K}throw new f({target:$.path,name:$.name,expectedOwnerId:Y,...typeof z?.ownerId==="string"?{observedOwnerId:z.ownerId}:{},...typeof z?.expiresAt==="number"?{observedExpiresAt:z.expiresAt}:{}})},release:async()=>{if(H&&D)return;_=!0,d(),await R;for(let z=0;z<y;z++){try{let K=!1;if(await o(async()=>{let W;try{W=await j()}catch(V){if(H&&V.code==="ENOENT"){K=!0;return}throw V}if(W?.ownerId!==Y){K=!0;return}if($.onStep)await $.onStep("release-owner-confirmed");if(!await X())return;await A(G),K=!0})){if(H&&!K)throw new q(G,"release-not-confirmed",{code:"EIO"});D=K;return}await r()}catch(K){if(H)throw K;return}await O()}if(H)throw new q(G,"release-not-confirmed",{code:"ETIMEDOUT"})}}}import{randomUUID as X0}from"node:crypto";import{mkdir as S0,open as F,rename as f0,rm as R0}from"node:fs/promises";import{dirname as v}from"node:path";class c extends Error{constructor($){super("file or directory sync failed",{cause:$});this.name="AtomicSyncError"}}async function h0($,G,Q={}){await M0($,G,Q)}async function M0($,G,Q,Y){if(H)return b($,Q.serialize?Q.serialize(G):`${JSON.stringify(G,null,2)}
6
- `,{beforeRename:Q.beforeRename,stagePath:`${$}.${(Q.stageName??X0)()}.tmp`,onRenamed:Y,durable:Q.durable,durability:Q.durability,onOutcome:Q.onOutcome});await S0(v($),{recursive:!0});let Z=`${$}.${(Q.stageName??X0)()}.tmp`,J,_=!1;try{if(J=await F(Z,"wx",384),_=!0,await J.writeFile(Q.serialize?Q.serialize(G):`${JSON.stringify(G,null,2)}
7
- `,"utf8"),await J.chmod(384),Q.durable)try{await J.sync()}catch(D){throw new c(D)}if(await J.close(),J=void 0,await Q.beforeRename?.(),await f0(Z,$),_=!1,Y?.(),Q.durable){let D=await F(v($),"r");try{await D.sync()}catch(B){throw new c(B)}finally{await D.close()}}}finally{if(await J?.close().catch(()=>{}),_)await R0(Z,{force:!0}).catch(()=>{})}}async function w0($){if(H){await x($,"file");let Y=new q($,"directory-sync-unsupported",{code:"ENOTSUP"});throw Y.published=!0,Y}let G=await F($,"r");try{await G.sync()}finally{await G.close()}let Q=await F(v($),"r");try{await Q.sync()}finally{await Q.close()}}var c0=Object.freeze({sidebar:Object.freeze({name:"sidebar-write",ttlMs:1e4,timeoutMs:15000,renew:!0}),preferences:Object.freeze({name:"preferences",ttlMs:1e4,timeoutMs:2000,renew:!0})});
8
- export{c as ze,h0 as Ae,M0 as Be,w0 as Ce,K0 as De,N0 as Ee,G0 as Fe,f as Ge,A0 as He,c0 as Ie};
File without changes