UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.98 kB
import{a as e,t}from"./git-operation.worker-fs-safe-2XqdJR5K.mjs";import{t as n}from"./git-operation.worker-path-guards-B73RPnzx.mjs";import{i as r,n as i,r as a}from"./git-operation.worker-staged-inputs-DZiTgX91.mjs";import{d as o,g as s,p as c,u as l}from"./git-operation.worker-workspace-manifest-DsRMcvMP.mjs";import u from"node:fs/promises";import d from"node:path";function reconciliationEntries(e,t=r(e),n){let i=l(n);return e.filter(e=>!o(e.path,i.has(e.path)||a(e.path,t),n!==void 0))}function reconciliationDirectories(e,t,n){let r=l(n);return(e??[]).filter(e=>!o(e,r.has(e)||a(e,t),n!==void 0))}async function removeDerivedWorkspaceDescendants(e,t,n,r){for(let i of await e.list(t,{withFileTypes:!0})){let a=t?`${t}/${i.name}`:i.name;c(a)||(o(a,await n(a),r)?await removeDerivedWorkspaceEntry(e,a,i.isDirectory):i.isDirectory&&(await removeDerivedWorkspaceDescendants(e,a,n,r),(await e.list(a)).length===0&&await e.remove(a)))}}async function removeDerivedWorkspaceEntry(e,n,r){if(r){let r;try{r=await e.list(n,{withFileTypes:!0})}catch(e){if(!(e instanceof t)||![`not-found`,`path-alias`].includes(e.code))throw e;r=void 0}for(let t of r??[])await removeDerivedWorkspaceEntry(e,`${n}/${t.name}`,t.isDirectory)}await e.remove(n).catch(e=>{if(!(e instanceof t)||e.code!==`not-found`)throw e})}async function hasWorkspaceSymlinkAncestor(e,t){for(let n of s(t))if((await u.lstat(d.join(e,n)).catch(()=>void 0))?.isSymbolicLink())return!0;return!1}async function prepareNonDirectoryTargets(t,r,a,o,s=!1){let c=await e(t,{assertBeforeMutation:o}),l=a??i(c);for(let e of r)(await u.lstat(d.join(t,e.path)).catch(async r=>{if(!(n(r,`ENOENT`)||n(r,`ENOTDIR`)||await hasWorkspaceSymlinkAncestor(t,e.path)))throw r}))?.isDirectory()&&!await hasWorkspaceSymlinkAncestor(t,e.path)&&(await removeDerivedWorkspaceDescendants(c,e.path,l,s),(await c.list(e.path)).length===0&&await c.remove(e.path))}export{prepareNonDirectoryTargets,reconciliationDirectories,reconciliationEntries};