"use strict";var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var s=(r,e)=>d(r,"name",{value:e,configurable:true});var S=(r,e)=>{for(var t in e)d(r,t,{get:e[t],enumerable:true})};var R=(r,e,t,o)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let n of P(e))if(!y.call(r,n)&&n!==t)d(r,n,{get:()=>e[n],enumerable:!(o=E(e,n))||o.enumerable})}return r};var h=r=>R(d({},"__esModule",{value:true}),r);var T={};S(T,{cleanupPendingServicePartitionDirectories:()=>u,getServiceIdsFromPartitions:()=>O,getServicePartitionsDirectory:()=>l,removeServicePartitionDirectory:()=>x});module.exports=h(T);var i=require("fs-extra");var v=require("../environment-remote");const m=new Set(["EACCES","EBUSY","ENOTEMPTY","EPERM"]);const a=require("../preload-safe-debug")("Ferdium:ServiceHelpers");const l=s((...r)=>{return(0,v.userDataPath)("Partitions",...[r].flat())},"getServicePartitionsDirectory");const f=s(()=>(0,v.userDataPath)("pending-service-partition-removals.json"),"getPendingPartitionRemovalsFile");const g=s(()=>{const r=f();if(!(0,i.pathExistsSync)(r)){return[]}try{const e=(0,i.readJsonSync)(r);if(!Array.isArray(e)){return[]}return e.filter(t=>typeof t==="string"&&t.length>0&&!t.includes("..")&&!t.includes("/")&&!t.includes("\\"))}catch(e){a("Unable to read pending service partition removals",e);return[]}},"readPendingPartitionRemovals");const p=s(r=>{const e=f();try{if(r.length===0){if((0,i.pathExistsSync)(e)){(0,i.removeSync)(e)}return}(0,i.writeJsonSync)(e,[...new Set(r)])}catch(t){a("Unable to persist pending service partition removals",t)}},"writePendingPartitionRemovals");const F=s(r=>{p([...g(),r])},"deferPartitionRemoval");const u=s(()=>{const r=g();if(r.length===0){return}const e=[];for(const t of r){const o=l(t);try{(0,i.removeSync)(o);a(`Removed deferred service partition "${o}"`)}catch(n){const c=n.code;if(c!=="ENOENT"){if(c!==void 0&&m.has(c)){e.push(t)}a(`Unable to remove deferred service partition "${o}"`,n)}}}p(e)},"cleanupPendingServicePartitionDirectories");const x=s((r="",e=false)=>{const t=`${e?"service-":""}${r}`;const o=l(t);try{(0,i.removeSync)(o)}catch(n){const c=n.code;if(c==="ENOENT"){return}if(c!==void 0&&m.has(c)){F(t);a(`Service partition "${o}" is still in use; deferring removal until next app start`,n);return}a(`Unable to remove service partition "${o}"`,n)}},"removeServicePartitionDirectory");async function O(){const r=(0,i.readdirSync)(l());return r.filter(e=>e!=="__chrome_extension")}s(O,"getServiceIdsFromPartitions");u();
