openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.62 kB
JavaScript
import{K as e,an as t,ln as n,mn as r}from"./sqlite-readonly-runtime-process-manifest-DDSkIpjb.mjs";import i,{constants as a}from"node:fs";import"node:fs/promises";import{types as o}from"node:util";var MutationAuthorityError=class extends n{rejection;constructor(e){super(`denied-path`,`mutation authority rejected the operation`,{cause:e}),this.rejection=e}};function isMutationAuthorityError(e){try{return e instanceof MutationAuthorityError}catch{return!1}}function assertSynchronousCallbackResult(e,t){if(e!==null&&(typeof e==`object`||typeof e==`function`)&&typeof e.then==`function`)throw Promise.resolve(e).catch(()=>void 0),TypeError(`${t} must be synchronous`);if(o.isGeneratorObject(e))throw TypeError(`${t} must be synchronous`)}function composeMutationAssertions(e,t){if(e||t)return()=>{try{assertSynchronousCallbackResult(e?.(),`assertBeforeMutation`),assertSynchronousCallbackResult(t?.(),`assertBeforeMutation`)}catch(e){throw new MutationAuthorityError(e)}}}function rethrowMutationAuthorityError(e){throw isMutationAuthorityError(e)?e.rejection:e}function assertOwnedDirectory(e,t){if(t.isSymbolicLink()||!t.isDirectory())throw new n(`not-file`,`directory mode target must be a real directory`);if(!r(e,t))throw new n(`path-mismatch`,`directory changed before its mode could be applied`)}function finalizeCreatedDirectoryModeSync(e,r){if(r===void 0||!e.created||process.platform===`win32`)return;let a=t(()=>i.fstatSync(e.fd,{bigint:!0}));assertOwnedDirectory(a,a),i.fchmodSync(e.fd,r&4095);let o=t(()=>i.fstatSync(e.fd,{bigint:!0}),a);if(assertOwnedDirectory(a,o),(o.mode&4095n)!==BigInt(r&4095))throw new n(`path-mismatch`,`created directory mode could not be finalized`)}function ownDirectoryMode(e){let t=Promise.resolve(),r,enqueue=e=>{if(r)return Promise.reject(new n(`path-mismatch`,`directory mode owner is closed`));let i=t.then(e);return t=i.catch(()=>void 0),i},i={verify:t=>enqueue(async()=>{t?.(),await e.inspect(),t?.()}),apply:(t,r={})=>enqueue(async()=>{t&=4095,r.check?.();let i=await e.inspect();if(r.check?.(),i===t&&!r.beforeChmod&&!r.check)return;i!==t&&(await e.prepareChmod?.(),r.check?.()),await r.beforeChmod?.(),r.check?.(),await e.inspect(),r.check?.();let a;if(i!==t){r.check?.();try{await e.chmod(t)}catch(t){if(!e.ignoreChmodError)throw t}try{r.check?.()}catch(e){a={error:e}}await e.verifyChmod?.()}let o=await e.inspect();if(a)throw a.error;if(r.check?.(),!e.ignoreChmodError&&o!==t)throw new n(`path-mismatch`,`directory final mode could not be verified`)}),close(){return r??=t.then(e.close),r}};return e.inspectCanonical&&(i.verifyCanonical=async()=>{let t=!1;return await enqueue(async()=>{t=e.inspectCanonical()!==void 0}),t}),i}function nodeDarwinDirectoryMetadataFlags(){if(process.platform!==`darwin`||process.arch!==`x64`&&process.arch!==`arm64`)throw new n(`helper-unavailable`,`Darwin directory metadata descriptors are unavailable`);return 32768|a.O_DIRECTORY|a.O_NOFOLLOW|a.O_NONBLOCK}function nodeDirectorySearchOnlyFlags(){if(process.arch===`x64`||process.arch===`arm64`){if(process.platform===`darwin`)return{flags:1073741824,proc:!1};if(process.platform===`linux`)return{flags:2097152,proc:!0}}}const s=/* @__PURE__ */ new Map;let c=!1;function pathStillMatchesReceipt(e){if(!e.identity)return!1;try{let t=i.lstatSync(e.path,{bigint:!0});return(!e.singleLinkFile||t.isFile()&&t.nlink===1n)&&r(t,e.identity)}catch{return!1}}function removeRegisteredPathSync(e){e.singleLinkFile?i.unlinkSync(e.path):i.rmSync(e.path,{force:!0,recursive:e.recursive})}function cleanupEntrySync(e){e.cleanupSync?e.cleanupSync():pathStillMatchesReceipt(e)&&removeRegisteredPathSync(e)}function cleanupRegisteredTempPathsSync(){for(let e of s.values())try{cleanupEntrySync(e)}catch{}s.clear()}function registerTempPathForExit(e,t){c||(c=!0,process.once(`exit`,cleanupRegisteredTempPathsSync));let n={path:e,recursive:t?.recursive===!0,identity:t?.identity,singleLinkFile:t?.singleLinkFile,cleanupSync:t?.cleanupSync};s.set(e,n);let unregister=(()=>{s.get(e)===n&&s.delete(e)});return unregister.setIdentity=e=>{n.identity=e},unregister}function annotateReadOnlyOpenError(t,n){if(t instanceof Error&&t.code===`EROFS`)try{let r=t;r.path=n,r.syscall=`open`,r.message=`EROFS: read-only filesystem, open '${e(n)}'`}catch{}}export{nodeDirectorySearchOnlyFlags as a,assertSynchronousCallbackResult as c,rethrowMutationAuthorityError as d,nodeDarwinDirectoryMetadataFlags as i,composeMutationAssertions as l,registerTempPathForExit as n,ownDirectoryMode as o,finalizeCreatedDirectoryModeSync as r,MutationAuthorityError as s,annotateReadOnlyOpenError as t,isMutationAuthorityError as u};