openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.66 kB
JavaScript
import{C as e,x as t}from"./disk-budget.worker-worker-cpu-C96zaKF5.mjs";import{a as n,l as r}from"./disk-budget.worker-sqlite-lifecycle-errors-BU4Ayp4j.mjs";import{$t as i,Wt as a}from"./disk-budget.worker-sqlite-worker-operation-settlement-9_4LJ7KU.mjs";import{M as o}from"./disk-budget.worker-spawn-diagnostics-CmOy7s7V.mjs";import{f as s,t as c}from"./disk-budget.worker-sqlite-source-handle-BpY0RjeQ.mjs";import{m as l}from"./disk-budget.worker-windows-appcontainer-spawn-399d5Yww.mjs";import{ct as u,dt as d,ft as f,lt as p,st as m}from"./disk-budget.worker-sqlite-schema-issues-KCjdLMTx.mjs";import h from"node:fs";function tryInspectSqliteReadOnlyInProcess(e,t,n={}){let r=h.realpathSync.native(e),i;try{i=d(r)}catch(e){if(e instanceof m)return;throw e}let a=f(r),o=n.preserveSourceArtifacts===!0,s=!o&&n.allowClosedWal&&!a.wal&&!a.shm&&!a.journal;if(i===`empty`||i===`wal`&&!(a.wal&&a.shm)&&!s||o&&(i!==`wal`||a.journal))return;let read=e=>{try{e.exec(`PRAGMA busy_timeout = 30000; PRAGMA trusted_schema = OFF; BEGIN;`),e.prepare(`PRAGMA schema_version;`).get()}catch(e){let t;try{t=d(r)}catch(e){if(e instanceof m)return;throw e}let n=f(r);if(t===`wal`&&!(n.wal&&n.shm)||t===`rollback`&&n.journal&&u(e)||o&&u(e))return;throw e}let n=t(e);return e.exec(`ROLLBACK;`),{value:n}};try{return c(r,`source`,read,{readOnlyShm:o})}catch(e){if(i===`wal`&&s&&n.snapshotAfterClosedWalFailure||o&&isSqliteCantOpenError(e))return;throw e}}function isSqliteCantOpenError(e){return i(e)===14}function readBackupEngineImage(e,t){try{var n=l();return readEngineAnchorIdentity(n.u(o(e,{readOnly:!0})),t)}catch(e){n.e=e}finally{n.d()}}function readEngineAnchorIdentity(e,t){let n=s(e);if(!n)return{engine:`sqlite`};let r=n[0];if(n.length!==1||r?.engine!==`postgres`||typeof r.store_id!=`string`||typeof r.schema!=`string`||!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(r.schema))throw Error(`Invalid PostgreSQL anchor: ${t}. Restore its matched backup.`);return{engine:`postgres`,storeId:r.store_id,namespace:r.schema}}async function readBackupEngineInProcess(e,t=!1){return inspectPhysicalStoreInProcess(e,t,t=>readEngineAnchorIdentity(t,e))}async function inspectPhysicalStoreInProcess(i,s,c){if(!s)try{let e=tryInspectSqliteReadOnlyInProcess(i,c);if(e)return e.value}catch(n){if(!(n instanceof t)&&!(n instanceof e)&&!a(n))throw n}let u=await p(i);return r({release(){if(!u.cleanup())throw new n(`SQLite engine inspection cleanup failed: ${i}`)}},`SQLite engine inspection`,()=>{try{var e=l();return c(e.u(o(u.location,{readOnly:!0})))}catch(t){e.e=t}finally{e.d()}})}export{inspectPhysicalStoreInProcess,readBackupEngineImage,readBackupEngineInProcess,readEngineAnchorIdentity};