import{s as e}from"./DrKWWDpL.js";import{t}from"./DYP3EJMY.js";import{i as n,l as r}from"./CX8DOZuw2.js";import{t as i}from"./DTkg6Mnx.js";import{t as a}from"./Y4KFZbvl.js";var o=e(t(),1),s=i(`exodus-archive`),c=`_archive`,l={project:`exodus-complete`,global:`exodus-complete`},u=[`-wal`,`-shm`];function d(e,t){return e===`project`?r(t):n()}function f(e,t){return(0,o.join)(d(e,t),c)}function p(e,t){return(0,o.join)(d(e,t),l[e])}function m(e,t){try{return(0,o.existsSync)(p(e,t))}catch{return!1}}function h(e,t,n){let r=p(e,n);(0,o.mkdirSync)(d(e,n),{recursive:!0});let i={version:1,scope:e,cleoVersion:a(),completedAt:new Date().toISOString(),archivedSources:[...t]},c=`${r}.tmp`;return(0,o.writeFileSync)(c,JSON.stringify(i,null,2)+`
`,`utf8`),(0,o.renameSync)(c,r),s.info({scope:e,markerPath:r,archivedSources:t},`exodus: wrote completion marker`),r}function g(e,t){(0,o.mkdirSync)(t,{recursive:!0});let n=(0,o.join)(t,(0,o.basename)(e));if((0,o.existsSync)(n)){let r=new Date().toISOString().replace(/[:.]/g,``).replace(/Z$/,`Z`);n=(0,o.join)(t,`${(0,o.basename)(e)}.${r}`)}try{(0,o.renameSync)(e,n)}catch{(0,o.copyFileSync)(e,n),(0,o.unlinkSync)(e)}return n}function _(e,t){if(!(0,o.existsSync)(e.path))return{name:e.name,sourcePath:e.path,archivedTo:null,action:`absent`};let n=f(e.targetScope,t),r=g(e.path,n);for(let t of u){let r=`${e.path}${t}`;if((0,o.existsSync)(r))try{g(r,n)}catch(t){s.warn({err:t,sidecar:r,sourceName:e.name},`exodus-archive: failed to archive sidecar (non-fatal)`)}}return s.info({sourceName:e.name,sourcePath:e.path,archivedTo:r,scope:e.targetScope},`exodus-archive: archived legacy source DB`),{name:e.name,sourcePath:e.path,archivedTo:r,action:`archived`}}function v(e,t){let n=[],r=new Set;for(let i of e)r.add(i.targetScope),n.push(_(i,t));let i=[];for(let n of r)h(n,e.filter(e=>e.targetScope===n).map(e=>e.name),t),i.push(n);return{sources:n,markersWritten:i}}export{m as a,p as i,_ as n,h as o,f as r,v as t};