UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 19.2 kB
import{i as e}from"./openclaw-state-read-home-dir-BQZX1pD2.mjs";import{$ as t,Wt as n,ot as r,tt as i,xt as a}from"./openclaw-state-read-sqlite-database-admission-Ck6VG7rE.mjs";import{a as o,n as s}from"./openclaw-state-read-tmp-openclaw-dir-C3Ynn93H.mjs";import{a as c}from"./openclaw-state-read-sqlite-lifecycle-errors-3AcFJUep.mjs";import{R as l,u,v as d}from"./openclaw-state-read-read-open-flags-CtNL1rJs.mjs";import{ct as f}from"./openclaw-state-read-root-symlink-policy-AldRD6ik.mjs";import{n as p,s as m}from"./openclaw-state-read-fs-safe-CpAHBauR.mjs";import{T as h,_ as g,b as _,f as v,g as y,i as b,m as x,n as S,p as C,r as w,t as T,u as E,v as D,w as O}from"./openclaw-state-read-sqlite-snapshot-capacity-error-Df9fZtJA.mjs";import{n as k}from"./openclaw-state-read-positional-read-zdUE4ydg.mjs";import{n as A,o as j}from"./openclaw-state-read-node-sqlite-UqZdY7HG.mjs";import{r as M}from"./openclaw-state-read-sqlite-schema-catalog-DLcl4287.mjs";import N from"node:fs";import P from"node:path";import"node:fs/promises";import{createHash as F,randomUUID as I}from"node:crypto";function sameFileContentsSync(e,t,n={}){let r=u(n.maxBytes)??1/0,i=Math.min(r,2**53-1),tooLarge=()=>new l(`too-large`,`file comparison exceeds ${i} bytes`);for(let n of[e,t]){let e=N.fstatSync(n,{bigint:!0});if(!e.isFile())throw new l(`not-file`,`file comparison requires regular-file descriptors`);if(e.size>BigInt(i))throw tooLarge()}let a=Buffer.allocUnsafe(Math.min(1048576,Math.max(1,i))),o=Buffer.allocUnsafe(a.length),s=0;for(;;){let n=Math.min(a.length,i-s);if(n===0){let n=N.readSync(e,a,0,1,s),r=N.readSync(t,o,0,1,s);if(n!==0||r!==0)throw tooLarge();return!0}let r=k(e,a.subarray(0,n),s),c=k(t,o.subarray(0,n),s);if(r!==c||!a.subarray(0,r).equals(o.subarray(0,c)))return!1;if(r<n)return!0;s+=r}}function finiteNonNegativeNumber(e){let t=Number(e);return Number.isFinite(t)&&t>=0?t:null}function findExistingDiskSpacePath(e){let t=P.resolve(e);for(;;)try{return N.statSync(t).isDirectory()?t:P.dirname(t)}catch{let e=P.dirname(t);if(e===t)return null;t=e}}function tryReadDiskSpace(e){let t=findExistingDiskSpacePath(e);if(!t)return null;try{let n=N.statfsSync(t),r=finiteNonNegativeNumber(n.bsize),i=finiteNonNegativeNumber(n.bavail);if(r===null||i===null)return null;let a=finiteNonNegativeNumber(n.blocks);return{targetPath:e,checkedPath:t,availableBytes:r*i,totalBytes:a===null?null:r*a}}catch{return null}}function formatDiskSpaceBytes(e){let t=e/1048576,n=Math.max(0,Math.round(t));if(n<1024)return`${n} MiB`;let r=t/1024;return`${r.toFixed(+(r<10))} GiB`}async function backupNodeSqliteDatabase(e,t,n){let r=setInterval(()=>{},100);try{let r=await a().backup(e,j(t),{progress:n});return n?.({totalPages:r,remainingPages:0}),r}finally{clearInterval(r)}}async function copySqliteFile(e,t,n,r={}){let{beforeByteCopy:i,clone:a=`auto`}=r,o=await p(P.dirname(e)),s=await p(P.dirname(t)),c,copy=r=>s.copyIn(P.basename(t),{relativePath:P.basename(e),root:{stat:e=>o.stat(e),open:async(t,r)=>{let i=await o.open(t,r);try{if(!f(n,await i.handle.stat({bigint:!0})))throw Error(`SQLite copy source changed: ${e}`);return i}catch(e){throw await i.handle.close(),e}}}},{clone:r,...i?{maxBytes:Number(n.size)}:{},sourceHardlinks:`allow`,overwrite:!1,mode:384,durable:!0,onDestinationPublished:e=>{c=e}});if(i&&a===`auto`)try{await copy(`always`)}catch(e){if(c||!(e instanceof l)||!(e.code===`unsupported-platform`||e.code===`helper-unavailable`&&e.message===`native file cloning is unavailable`))throw e;await i(Number(n.size)),await copy(`never`)}else await i?.(Number(n.size)),await copy(a);if(!c)throw Error(`SQLite copy was not published: ${t}`);return c}function createPrivateWindowsDirectory(e){let t=!1;try{m(P.resolve(e),{private:!0,assertBeforeMutation(){t=!0}})}catch(e){throw!t||e instanceof l&&e.code===`already-exists`?b(e):e}}function resolvePrivateSqliteSnapshotStagingRoot(e=process.env){try{return resolveSnapshotStagingRoot(e)}catch(e){throw e instanceof Error&&S(e)?new T(`SQLite snapshot staging root is unavailable: ${e.message}; free disk space/quota`,{cause:e}):e}}function resolveSnapshotStagingRoot(t){let n=t.OPENCLAW_UPDATE_IN_PROGRESS===`1`?t.TMPDIR?.trim():void 0;if(n&&P.isAbsolute(n))return s({preferredDir:P.join(n,`openclaw`),tmpdir:()=>n});let r=process.platform===`win32`?t.LOCALAPPDATA?.trim():void 0,i=process.platform===`win32`?`AppData/Local`:`.cache`,a=process.platform===`darwin`?`Library/Caches`:i,c=[t.XDG_CACHE_HOME?.trim(),r].find(e=>e&&P.isAbsolute(e))??P.join(e(t),a),l=o(t),u=F(`sha256`).update(l).digest(`hex`).slice(0,24);N.mkdirSync(c,{recursive:!0,mode:448});let d=s({preferredDir:P.join(c,`openclaw`),tmpdir:()=>c}),[f=``,...p]=P.relative(d,l).split(P.sep),m=p.length>0&&/^sqlite-[a-f0-9]{24}$/u.test(f)?f:`sqlite-${u}`,h=P.join(d,m);N.mkdirSync(h,{recursive:!0,mode:448});let g=N.lstatSync(h);if(!g.isDirectory()||process.getuid&&g.uid!==process.getuid()||process.platform!==`win32`&&g.mode&63)throw Error(`SQLite snapshot namespace must be a private user-owned directory`);return h}function createPrivateSqliteTempDirectorySync(e,t){if(process.platform!==`win32`)try{return N.mkdtempSync(P.join(e,t))}catch(e){throw b(e)}let n=P.join(e,`${t}${I()}`);return createPrivateWindowsDirectory(n),n}function sqliteSnapshotSourceFileSize(e){try{let t=N.statSync(e);return t.isFile()?t.size:0}catch(e){if(d(e,`ENOENT`))return 0;throw e}}function assertSqliteSnapshotSpace(e,t){let n=typeof e==`string`?[``,`-wal`,`-journal`].reduce((t,n)=>t+sqliteSnapshotSourceFileSize(e+n),0):M(e),r=tryReadDiskSpace(t);if(r&&r.availableBytes<n)throw Object.assign(/* @__PURE__ */ Error(`SQLite read-only snapshot needs ${formatDiskSpaceBytes(n)} (${n} bytes) near ${t}, but only ${formatDiskSpaceBytes(r.availableBytes)} (${r.availableBytes} bytes) is available. Free disk space before retrying.`),{code:`ENOSPC`})}function waitForSnapshotRetrySync(e){if(e+1>=10)return;let t=Math.min(80,10*2**e);t>0&&Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,t)}function acquireSqliteSnapshotReadToken(e){return h(e,`read`)}function sqliteSnapshotStagingError(e,n,r=!1,a){t(n,`snapshot`);let o=r,s=!1,l=!1,u;for(let t=0,r=n;t<8&&r instanceof Error;t+=1){l||=r instanceof AggregateError||r instanceof c;let{errcode:t,path:n}=r;s||=S(r),(s||typeof t==`number`&&[13,778,1034,1290].includes(t)||`${n??``}${P.sep}`.startsWith(`${e}${P.sep}`))&&(o=!0,typeof t==`number`&&(u=t)),r=r.cause}if(!o)return n;let d=s?`free disk space/quota`:`check filesystem health and write permissions`,f=``;if(s&&a)try{let t=sqliteSnapshotSourceFileSize(a)+sqliteSnapshotSourceFileSize(`${a}-wal`)+sqliteSnapshotSourceFileSize(`${a}-journal`),n=tryReadDiskSpace(e)?.availableBytes,r=N.existsSync(`${a}-wal`)&&N.existsSync(`${a}-shm`);f=`; estimated ${t} bytes needed; ${n===void 0?`available bytes unknown`:`${n} bytes available`}; source ${r?`has live WAL sidecars`:`has no live WAL sidecars`}`}catch{}let p=process.env.OPENCLAW_UPDATE_IN_PROGRESS===`1`?`TMPDIR`:`XDG_CACHE_HOME`,m=`${n instanceof Error?n.message:String(n)}${u===void 0?``:` (SQLite errcode=${u})`}; snapshot staging root ${r?e:P.dirname(e)}${f}: ${d} or set ${p} to a writable filesystem`,h=s&&!l&&i(n)!==`source`?new T(m,{cause:n}):Error(m,{cause:n});return w(n)?b(h):h}async function createSqliteSnapshotStagingDirectory(e=resolvePrivateSqliteSnapshotStagingRoot(),n=!1,r,i=!1){r?.throwIfAborted();try{return await allocateSqliteSnapshotStagingDirectory(e,n,r,i)}catch(e){throw e instanceof c||i&&e instanceof AggregateError||(r?.throwIfAborted(),t(e,`snapshot`)),e}}async function allocateSqliteSnapshotStagingDirectory(e=resolvePrivateSqliteSnapshotStagingRoot(),t=!1,n,r=!1){if(n?.throwIfAborted(),r){let r=new AbortController;return _((async()=>{let{allocateWorkerOwnedSqliteSnapshotDirectory:i}=await import(`./openclaw-state-read-sqlite-snapshot-staging-allocation-DZqHyqJs.mjs`);n?.throwIfAborted(),r.signal.throwIfAborted();let a=await i(e,t,n?AbortSignal.any([n,r.signal]):r.signal);if(y(a.directory),n?.aborted||r.signal.aborted){if(!await D(a.directory))throw new c(`SQLite snapshot cleanup failed: ${a.directory}`);n?.throwIfAborted(),r.signal.throwIfAborted()}return a.directory})(),()=>r.abort(/* @__PURE__ */ Error(`SQLite snapshot allocation stopped`)))}return createSqliteSnapshotStagingDirectorySync(e,t)}function createSqliteSnapshotStagingDirectorySync(e=resolvePrivateSqliteSnapshotStagingRoot(),t=!1){let n=createSqliteSnapshotStagingTokenSync(e,t);return y(n.directory,n.release),n.directory}function createSqliteSnapshotStagingTokenSync(e=resolvePrivateSqliteSnapshotStagingRoot(),t=!1){let n;try{try{n=createPrivateSqliteTempDirectorySync(e,t?`openclaw-sqlite-readonly-${process.pid}-`:O)}catch(t){throw sqliteSnapshotStagingError(e,t,!0)}return{directory:n,release:h(n,`create`)}}catch(e){throw n&&g(n),e}}function readUint32(e,t,n){return n===`LE`?e.readUInt32LE(t):e.readUInt32BE(t)}function sqliteWalChecksum(e,t,n=[0,0]){let[r,i]=n;for(let n=0;n<e.length;n+=8)r=r+readUint32(e,n,t)+i>>>0,i=i+readUint32(e,n+4,t)+r>>>0;return[r,i]}const L=1048576;function readWalGeneration(e){let t=Buffer.alloc(32);if(k(e,t,0)!==t.length)return;let n=t.readUInt32BE(0);if(n!==931071618&&n!==931071619)return;let r=n===931071618?`LE`:`BE`,i=t.readUInt32BE(8),[a,o]=sqliteWalChecksum(t.subarray(0,24),r);if(!(i<512||i>65536||i&i-1||t.readUInt32BE(24)!==a||t.readUInt32BE(28)!==o))return{header:t,byteOrder:r,frameBytes:24+i}}function copyCommittedWalFrames(e,t,n,r){let{header:i,byteOrder:a,frameBytes:o}=n;if(readWalGeneration(e)?.header.equals(i)!==!0)return!1;let s=i.subarray(16,24),c=[i.readUInt32BE(24),i.readUInt32BE(28)];writeFully(t,i,0);let l=32,u=Math.max(1,Math.floor(L/o)),d=Buffer.allocUnsafe(u*o);for(let n=32;n<r;){let i=d.subarray(0,Math.min(d.length,r-n)),u=k(e,i,n),f=0,p=!0;for(let e=0;e+o<=u;e+=o){let t=i.subarray(e,e+o);if(t.readUInt32BE(0)===0||!t.subarray(8,16).equals(s)){p=!1;break}let r=sqliteWalChecksum(t.subarray(24),a,sqliteWalChecksum(t.subarray(0,8),a,c));if(t.readUInt32BE(16)!==r[0]||t.readUInt32BE(20)!==r[1]){p=!1;break}c=r,f=e+o,t.readUInt32BE(4)!==0&&(l=n+f)}if(f>0&&writeFully(t,i.subarray(0,f),n),!p||f<i.length)break;n+=f}return N.ftruncateSync(t,l),N.fsyncSync(t),l}function writeFully(e,t,n){for(let r=0;r<t.length;){let i=N.writeSync(e,t,r,t.length-r,n+r);if(i<=0)throw Error(`SQLite WAL snapshot write made no progress`);r+=i}}function matchesCapturedWalPrefix(e,t,n){let r=N.openSync(t,`r`);try{let t=N.fstatSync(r);if(!t.isFile()||t.size!==n)return!1;let i=Buffer.allocUnsafe(Math.min(L,n)),a=Buffer.allocUnsafe(i.length);for(let t=0;t<n;t+=i.length){let o=Math.min(i.length,n-t),s=i.subarray(0,o),c=a.subarray(0,o);if(k(e,s,t)!==o||k(r,c,t)!==o||!s.equals(c))return!1}return!0}finally{N.closeSync(r)}}function prepareSqliteWalPrefixCopy(e,t,n){let r=readWalGeneration(e);if(r)return()=>{let i=N.fstatSync(e).size;if(!Number.isSafeInteger(i)||i<32)return!1;let a=N.openSync(t,`wx`,384),o;try{o=copyCommittedWalFrames(e,a,r,i)}finally{N.closeSync(a)}return o!==!1&&n()&&matchesCapturedWalPrefix(e,t,o)&&readWalGeneration(e)?.header.equals(r.header)===!0}}const R=Buffer.from([217,213,5,249,32,161,99,215]);var SqliteSourceChangedError=class extends Error{constructor(e,t){super(t?.attempts?`SQLite source did not stabilize (reason=${e}, attempts=${t.attempts}) after ${t.attempts} read-only inspection attempts. Wait a moment for write activity to settle, then retry the inspection`:`SQLite source changed during read-only inspection (reason=${e})`,t),this.reason=e}};function statIfPresent(e){try{return N.statSync(e,{bigint:!0})}catch(e){if(e.code===`ENOENT`)return;throw e}}function readSourceSidecars(e){return{journal:!!statIfPresent(`${e}-journal`),shm:!!statIfPresent(`${e}-shm`),wal:!!statIfPresent(`${e}-wal`)}}function openPinnedFile(e,t){let r;try{r=N.openSync(e,`r`)}catch(e){throw e.code===`ENOENT`?new SqliteSourceChangedError(`source-disappeared`):e}try{let i=N.fstatSync(r,{bigint:!0});t&&n(i,t);let a=statIfPresent(e);if(!i.isFile()||!a?.isFile()||!f(i,a))throw new SqliteSourceChangedError(`source-identity-changed`);return{descriptor:r,identity:i,pathname:e}}catch(e){throw N.closeSync(r),e}}function readSourceJournalMode(e,t){let n=openPinnedFile(e,t);try{let e=Buffer.alloc(20),t=N.readSync(n.descriptor,e,0,e.length,0);return assertPinnedIdentityUnchanged(n),t===0?`empty`:t!==e.length||e.subarray(0,16).toString(`utf8`)!==`SQLite format 3\0`?`unknown`:e[18]===2||e[19]===2?`wal`:`rollback`}finally{N.closeSync(n.descriptor)}}function assertPinnedIdentityUnchanged(e){let t=N.fstatSync(e.descriptor,{bigint:!0}),n=statIfPresent(e.pathname);if(!t.isFile()||!n?.isFile()||!f(e.identity,t)||!f(e.identity,n))throw new SqliteSourceChangedError(`source-identity-changed`)}function sourceMatchesCopy(e,t,n){let r=openPinnedFile(e,n);try{let e=N.openSync(t,`r`);try{if(!N.fstatSync(e).isFile())return!1;let t=sameFileContentsSync(r.descriptor,e);return assertPinnedIdentityUnchanged(r),t}finally{N.closeSync(e)}}finally{N.closeSync(r.descriptor)}}function assertExpectedSidecars(e,t){let n=readSourceSidecars(e);if(n.journal!==t.journal||n.wal!==t.wal)throw new SqliteSourceChangedError(`journal-state-changed`)}function isSqliteReadOnlyError(e){let t=e;for(let e=0;e<8&&t&&typeof t==`object`;e+=1){let e=t;if(typeof e.errcode==`number`&&(e.errcode&255)==8)return!0;t=e.cause}return!1}function rollbackJournalReferencesSuperJournal(e){let t=N.openSync(e,`r`);try{let e=N.fstatSync(t).size;if(e<16)return!1;let n=Buffer.allocUnsafe(16);if(N.readSync(t,n,0,n.length,e-n.length)!==n.length)return!1;let r=n.readUInt32BE(0);return r>0&&r<=e-20&&n.subarray(8).equals(R)}finally{N.closeSync(t)}}function syncPrivateSnapshot(e){let t=N.openSync(e,`r+`);try{N.fsyncSync(t)}finally{N.closeSync(t)}}function recoverPrivateJournalCopy(e){if(rollbackJournalReferencesSuperJournal(`${e}-journal`))throw Error(`SQLite hot rollback journal references a super-journal and cannot be recovered privately: ${e}`);let t=A(e);try{t.exec(`PRAGMA busy_timeout = 30000; PRAGMA trusted_schema = OFF;`),t.prepare(`PRAGMA schema_version;`).get()}finally{t.close()}N.rmSync(`${e}-journal`,{force:!0}),syncPrivateSnapshot(e)}function*createStableReadOnlyCopyInTempDirectory(e,t,n,r=n?P.dirname(n):resolvePrivateSqliteSnapshotStagingRoot(),i,a){let o=n;try{o??=createSqliteSnapshotStagingDirectorySync(r),assertSqliteSnapshotSpace(e,o);let n=P.join(o,`database.sqlite.partial`);if(process.platform!==`win32`&&N.chmodSync(o,448),readSourceJournalMode(e,i)!==t)throw new SqliteSourceChangedError(`journal-mode-changed`);let s=readSourceSidecars(e),c=!1;if(t===`wal`&&s.wal&&!s.journal){let t=openPinnedFile(`${e}-wal`);try{let r=prepareSqliteWalPrefixCopy(t.descriptor,`${n}-wal`,()=>sourceMatchesCopy(e,n,i));r&&(yield{sourcePath:e,targetPath:n,expectedSourceIdentity:i});let a=r?.();if(assertPinnedIdentityUnchanged(t),a===!1)throw new SqliteSourceChangedError(`wal-copy-unstable`);c=a===!0}finally{N.closeSync(t.descriptor)}}let l=[...s.journal?[`-journal`]:[],...s.wal?[`-wal`]:[]];if(c)assertExpectedSidecars(e,s);else if(l.length>0){for(let t of l)yield{sourcePath:`${e}${t}`,targetPath:`${n}${t}`};if(yield{sourcePath:e,targetPath:n,expectedSourceIdentity:i},!sourceMatchesCopy(e,n,i))throw new SqliteSourceChangedError(`main-changed-during-copy`);for(let t of l)if(!sourceMatchesCopy(`${e}${t}`,`${n}${t}`))throw new SqliteSourceChangedError(t===`-wal`?`wal-changed-during-copy`:`rollback-journal-changed-during-copy`);assertExpectedSidecars(e,s)}else{yield{sourcePath:e,targetPath:n,expectedSourceIdentity:i},assertExpectedSidecars(e,s);let t=a!==void 0||sourceMatchesCopy(e,n,i);if(assertExpectedSidecars(e,s),!t)throw new SqliteSourceChangedError(`main-changed-during-copy`)}if(readSourceJournalMode(e,i)!==t)throw new SqliteSourceChangedError(`journal-mode-changed`);if(a&&(s.journal||s.wal&&N.statSync(`${n}-wal`).size!==0))throw new SqliteSourceChangedError(`recovery-data-appeared`);return s.journal&&recoverPrivateJournalCopy(n),x(o,a)}catch(t){let r=o?sqliteSnapshotStagingError(o,t,!1,e):t;if(o&&n===void 0){let e=[r];if(!g(o,t=>e.push(t)))throw C(e,`SQLite snapshot preparation`)}throw r}}async function copyPreparedLocation(e){let t=e.next();for(;!t.done;){try{let{sourcePath:e,targetPath:n,expectedSourceIdentity:r}=t.value,i=openPinnedFile(e,r);try{await copySqliteFile(e,n,i.identity,{clone:`never`})}finally{try{assertPinnedIdentityUnchanged(i)}finally{N.closeSync(i.descriptor)}}}catch(n){t=e.throw(n);continue}t=e.next()}return t.value}async function createOnlineReadOnlyBackup(e,t,n,i){let a=typeof t==`object`?t.directory:await createSqliteSnapshotStagingDirectory(t,!1,n),o=P.join(a,`database.sqlite.partial`);try{process.platform!==`win32`&&N.chmodSync(a,448);let t=r(`source`,()=>A(e,{readOnly:!0}));try{t.exec(`PRAGMA busy_timeout = 30000; PRAGMA trusted_schema = OFF; BEGIN;`),t.prepare(`PRAGMA schema_version;`).get(),assertSqliteSnapshotSpace(t,a),await _(backupNodeSqliteDatabase(t,o,i)),t.exec(`ROLLBACK;`)}finally{t.isOpen&&t.close()}return syncPrivateSnapshot(o),x(a)}catch(n){let r=sqliteSnapshotStagingError(a,n,!1,e);return E(a,r,`SQLite online backup`,typeof t==`object`)}}function*prepareArtifactPreservingCopy(e,t,n,r){let i=N.realpathSync.native(e);for(let e=0;;e+=1)try{return yield*createStableReadOnlyCopyInTempDirectory(i,readSourceJournalMode(i,n),typeof t==`object`?t.directory:void 0,typeof t==`string`?t:void 0,n,r)}catch(n){if(typeof t==`object`&&v(t.directory,n),!(n instanceof SqliteSourceChangedError))throw n;if(e+1>=10)throw new SqliteSourceChangedError(n.reason,{cause:n,attempts:10});waitForSnapshotRetrySync(e)}}const z=/* @__PURE__ */ new Set([`wal-copy-unstable`,`main-changed-during-copy`,`wal-changed-during-copy`]);async function prepareSqliteReadOnlyCopyInProcess(e,t,n){try{return await copyPreparedLocation(prepareArtifactPreservingCopy(e,t,n))}catch(r){if(!(r instanceof SqliteSourceChangedError)||!z.has(r.reason))throw r;let i=N.realpathSync.native(e),a=openPinnedFile(i,n);try{let e=readSourceSidecars(i);if(readSourceJournalMode(i,n)!==`wal`||!e.wal||!e.shm||e.journal)throw r;let o=await createOnlineReadOnlyBackup(i,t);try{assertPinnedIdentityUnchanged(a)}catch(e){throw o.cleanup(),e}return o}finally{N.closeSync(a.descriptor)}}}async function prepareSqliteReadOnlyLocationFromOwnedDatabase(e,t,n,r){let assertReady=()=>{if(n?.throwIfAborted(),t(),!e.isOpen||e.isTransaction)throw Error(`SQLite inspection requires an open owner outside a transaction`)};assertReady();let i=await createSqliteSnapshotStagingDirectory(void 0,!1,n,r===`async`);try{assertReady(),assertSqliteSnapshotSpace(e,i);let r=P.join(i,`database.sqlite.partial`);return await _(backupNodeSqliteDatabase(e,r)),n?.throwIfAborted(),t(),x(i)}catch(e){let t=[e];throw!await D(i,e=>t.push(e))&&r===`async`?C(t,`Owned SQLite snapshot preparation`):e}}export{readSourceJournalMode as a,createSqliteSnapshotStagingDirectory as c,resolvePrivateSqliteSnapshotStagingRoot as d,prepareSqliteReadOnlyLocationFromOwnedDatabase as i,createSqliteSnapshotStagingDirectorySync as l,isSqliteReadOnlyError as n,readSourceSidecars as o,prepareSqliteReadOnlyCopyInProcess as r,acquireSqliteSnapshotReadToken as s,SqliteSourceChangedError as t,createPrivateSqliteTempDirectorySync as u};