// The roots, as the doctor reports them (`umtool doctor`, /settings/system): // where projects are read, where their out/ goes, where the cache is -- and a // cache left where it used to live (under SONG_DATA, before release 17), which // is derived and safe to delete once `umtool index` has rebuilt the new one. // // Shared by the CLI and the app (P5 moved it out of bin/umtool.mjs). import { CACHE_DIR, INDEX_DIR, MEDIA_ROOT, MEDIA_TIERED, OLD_CACHE_DIR, REPORTS_ROOT } from "../paths.mjs"; import { measureTree, mediaRootProblem, pathState } from "../report/storage.mjs"; /** * @param {{ measureOld?: boolean }} [opts] `measureOld` false skips sizing the * old cache (a page render does not walk a tree) */ export async function rootsReport({ measureOld = true } = {}) { const isDir = async (p) => (await pathState(p)).kind === "dir"; const problem = await mediaRootProblem(); const oldPresent = OLD_CACHE_DIR !== CACHE_DIR && (await isDir(OLD_CACHE_DIR)); return { ok: !problem, reports: { path: REPORTS_ROOT, present: await isDir(REPORTS_ROOT) }, media: { path: MEDIA_ROOT, tiered: MEDIA_TIERED, present: await isDir(MEDIA_ROOT), problem }, cache: { path: CACHE_DIR, present: await isDir(CACHE_DIR), index: await isDir(INDEX_DIR) }, oldCache: oldPresent ? { path: OLD_CACHE_DIR, present: true, ...(measureOld ? { bytes: (await measureTree(OLD_CACHE_DIR)).bytes } : {}) } : { path: OLD_CACHE_DIR, present: false }, }; }