import{r as e,t}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as n}from"./chunk-HWKDQ44K-BJxdK4fT.mjs";var r={name:`du`,summary:`estimate file space usage`,usage:`du [OPTION]... [FILE]...`,options:[`-a          write counts for all files, not just directories`,`-h          print sizes in human readable format`,`-s          display only a total for each argument`,`-c          produce a grand total`,`--max-depth=N  print total for directory only if N or fewer levels deep`,`    --help  display this help and exit`]},i={allFiles:{short:`a`,type:`boolean`},humanReadable:{short:`h`,type:`boolean`},summarize:{short:`s`,type:`boolean`},grandTotal:{short:`c`,type:`boolean`},maxDepth:{long:`max-depth`,type:`number`}},a={name:`du`,async execute(a,o){if(t(a))return e(r);let l=n(`du`,a,i);if(!l.ok)return l.error;let u={allFiles:l.result.flags.allFiles,humanReadable:l.result.flags.humanReadable,summarize:l.result.flags.summarize,grandTotal:l.result.flags.grandTotal,maxDepth:l.result.flags.maxDepth??null},d=l.result.positional;d.length===0&&d.push(`.`);let f=``,p=``,m=0;for(let e of d){let t=o.fs.resolvePath(o.cwd,e);try{await o.fs.stat(t);let n=await s(o,t,e,u,0);f+=n.output,m+=n.totalSize,p+=n.stderr}catch{p+=`du: cannot access '${e}': No such file or directory
`}}return u.grandTotal&&d.length>0&&(f+=`${c(m,u.humanReadable)}	total
`),{stdout:f,stderr:p,exitCode:p?1:0}}},o=1e3;async function s(e,t,n,r,i){let a={output:``,totalSize:0,stderr:``};if(i>o)return a;try{let o=await e.fs.stat(t);if(!o.isDirectory)return a.totalSize=o.size,(r.allFiles||i===0)&&(a.output=c(o.size,r.humanReadable)+`	`+n+`
`),a;let l=0,u=[];if(e.fs.readdirWithFileTypes){let n=await e.fs.readdirWithFileTypes(t),r=n.filter(e=>e.isFile),i=n.filter(e=>e.isDirectory);for(let n=0;n<r.length;n+=100){let i=r.slice(n,n+100),a=await Promise.all(i.map(async n=>{let r=t===`/`?`/${n.name}`:`${t}/${n.name}`;try{let t=await e.fs.stat(r);return{name:n.name,isDirectory:!1,size:t.size}}catch{return{name:n.name,isDirectory:!1,size:0}}}));u.push(...a)}u.push(...i.map(e=>({name:e.name,isDirectory:!0})))}else{let n=await e.fs.readdir(t);for(let r=0;r<n.length;r+=100){let i=n.slice(r,r+100),a=await Promise.all(i.map(async n=>{let r=t===`/`?`/${n}`:`${t}/${n}`;try{let t=await e.fs.stat(r);return{name:n,isDirectory:t.isDirectory,size:t.isDirectory?void 0:t.size}}catch{return{name:n,isDirectory:!1,size:0}}}));u.push(...a)}}u.sort((e,t)=>e.name.localeCompare(t.name));let d=u.filter(e=>!e.isDirectory);for(let e of d){let t=e.size??0;if(l+=t,r.allFiles&&!r.summarize){let i=n===`.`?e.name:`${n}/${e.name}`;a.output+=c(t,r.humanReadable)+`	`+i+`
`}}let f=u.filter(e=>e.isDirectory);for(let o=0;o<f.length;o+=100){let c=f.slice(o,o+100),u=await Promise.all(c.map(async a=>{let o=t===`/`?`/${a.name}`:`${t}/${a.name}`,c=n===`.`?a.name:`${n}/${a.name}`;return{name:a.name,result:await s(e,o,c,r,i+1)}}));u.sort((e,t)=>e.name.localeCompare(t.name));for(let{result:e}of u)l+=e.totalSize,r.summarize||(r.maxDepth===null||i+1<=r.maxDepth)&&(a.output+=e.output)}a.totalSize=l,(r.summarize||r.maxDepth===null||i<=r.maxDepth)&&(a.output+=`${c(l,r.humanReadable)}	${n}
`)}catch{a.stderr=`du: cannot read directory '${n}': Permission denied
`}return a}function c(e,t){return t?e<1024?`${e}`:e<1024*1024?`${(e/1024).toFixed(1)}K`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)}M`:`${(e/(1024*1024*1024)).toFixed(1)}G`:String(Math.ceil(e/1024)||1)}var l={name:`du`,flags:[{flag:`-a`,type:`boolean`},{flag:`-h`,type:`boolean`},{flag:`-s`,type:`boolean`},{flag:`-c`,type:`boolean`},{flag:`--max-depth`,type:`value`,valueHint:`number`}],needsFiles:!0};export{l as n,a as t};
//# sourceMappingURL=chunk-RPNGRAAP-yHFoBjjv.mjs.map