commit ad05a31e18163fb5908cf30961a65009c6df73a2
parent 3c91f59ca726ed8f949da093fa16a056eafe9513
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 11:33:31 -0500
local media: a library may not contain anything the archive owns either
Re-review follow-up F1. libraryLocationProblem refused a library INSIDE a
channel's media dir, a saved-video store, the corpus, a storage location or the
checkout; only the corpus was checked the other way. It now also refuses one
that CONTAINS any of them ("The library directory contains <what> (<root>);
choose a directory that does not."): the library is read-only, so nothing is
lost, but a scan would offer archive-owned media as recordings. Test: a
library over a channel's media tier, the store, a storage location and the
checkout; two overlap tests accept the more specific sentence.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat:
4 files changed, 45 insertions(+), 26 deletions(-)
diff --git a/common/controller/localMediaImport.test.ts b/common/controller/localMediaImport.test.ts
@@ -79,7 +79,7 @@ test("retired data layout refuses preview", async (t) => {
test("source overlapping corpus is refused before writes", async (t) => {
const f=await fixture(t);
await writeFile(path.join(f.channel,"config.json"),JSON.stringify({...f.config,localMedia:{...f.config.localMedia,directory:f.root}}));
- await assert.rejects(previewLocalMedia(f.paths,"sample"),/overlap/);
+ await assert.rejects(previewLocalMedia(f.paths,"sample"),/overlap|The library directory contains the corpus/);
assert.deepEqual(await readdir(f.channel),["config.json"]);
});
test("cancellation and empty selection write nothing", async (t) => {
diff --git a/common/controller/localMediaLocation.test.ts b/common/controller/localMediaLocation.test.ts
@@ -70,3 +70,27 @@ test("a misplaced library written into the config by hand is refused at preview"
localMedia: { sourceId: "library-1", directory: path.join(STORE, "lib") } });
await assert.rejects(previewLocalMedia(paths, "sample"), /inside the saved-video store/);
});
+
+// Re-review F1: a library that CONTAINS an owned tree is refused too.
+test("a library containing a channel's media dir, the store, a storage location or the checkout is refused", async () => {
+ const cases: Array<[string, RegExp]> = [
+ [path.join(DRIVE, "media-tier"), /contains channel "other"'s media directory/],
+ [ROOT, /contains channel "other"'s media directory/],
+ [path.dirname(paths.monorepoRoot), /contains the Archilyzer checkout/],
+ ];
+ for (const [dir, re] of cases) {
+ const problem = await libraryLocationProblem(paths, dir);
+ assert.ok(problem, dir);
+ assert.match(problem!, re);
+ assert.match(problem!, /; choose a directory that does not\.$/);
+ }
+ const { mkdirSync } = await import("node:fs");
+ const holder = path.join(ROOT, "holder");
+ mkdirSync(holder, { recursive: true });
+ const only = (root: string, what: RegExp) =>
+ libraryLocationProblem({ channelsDir: "/nonexistent-archilyzer-test/channels", savedVideosDir: root }, path.dirname(root), { channels: [] })
+ .then((p) => assert.match(p ?? "", what));
+ await only(path.join(holder, "store"), /contains the saved-video store/);
+ assert.match(await libraryLocationProblem({ channelsDir: "/nonexistent-archilyzer-test/channels" }, path.dirname(LOCATION), { channels: [] }) ?? "",
+ /contains storage location "Cold drive"/);
+});
diff --git a/common/controller/localMediaLocation.ts b/common/controller/localMediaLocation.ts
@@ -12,7 +12,7 @@ import { listChannelConfigs } from "./channels";
// in-place media), the saved-video store (the global one and a channel's own
// `savedVideosDir`), a channel's media tier (`mediaDir`, on another drive), a
// configured storage location (whose tree a relocation rewrites), or the
-// Archilyzer checkout. One sentence for each, naming what it is inside.
+// Archilyzer checkout — nor contain one. One sentence for each, naming it.
//
// Checked where the library is configured (configureLocalMedia, the New
// channel form) AND where it is used (the import's context), since a config
@@ -43,38 +43,33 @@ export async function libraryLocationProblem(
opts: { channels?: Array<{ slug: string; config: { mediaDir?: string; savedVideosDir?: string } }> } = {},
): Promise<string | null> {
const lib = path.resolve(directory);
- const refuse = (what: string, root: string) =>
- `The library directory is inside ${what} (${root}); choose a directory outside it.`;
const channels = opts.channels ?? (await listChannelConfigs(paths as Paths).catch(() => []));
- // Most specific first, so the sentence names the narrowest owner.
+ // What the archive owns, most specific first, so a sentence names the
+ // narrowest owner.
+ const owned: Array<{ what: string; root: string }> = [];
for (const { slug, config } of channels) {
- if (config.mediaDir) {
- const root = await canonical(config.mediaDir);
- if (inside(root, lib)) return refuse(`channel "${slug}"'s media directory`, root);
- }
- if (config.savedVideosDir) {
- const root = await canonical(config.savedVideosDir);
- if (inside(root, lib)) return refuse(`channel "${slug}"'s saved-video store`, root);
- }
- }
- if (paths.savedVideosDir) {
- const root = await canonical(paths.savedVideosDir);
- if (inside(root, lib)) return refuse("the saved-video store", root);
+ if (config.mediaDir) owned.push({ what: `channel "${slug}"'s media directory`, root: await canonical(config.mediaDir) });
+ if (config.savedVideosDir) owned.push({ what: `channel "${slug}"'s saved-video store`, root: await canonical(config.savedVideosDir) });
}
+ if (paths.savedVideosDir) owned.push({ what: "the saved-video store", root: await canonical(paths.savedVideosDir) });
// The corpus root when known (getPaths() always has it); a caller holding
// only `channelsDir` gets that tree checked.
- const corpus = await canonical(paths.transcriptsDir ?? paths.channelsDir);
- if (inside(corpus, lib)) return refuse("the corpus", corpus);
+ owned.push({ what: "the corpus", root: await canonical(paths.transcriptsDir ?? paths.channelsDir) });
let locations: Array<{ label: string; root: string }> = [];
try { locations = getSettings().storage?.locations ?? []; } catch { /* no settings: no locations */ }
for (const location of locations) {
- if (!location.root) continue;
- const root = await canonical(location.root);
- if (inside(root, lib)) return refuse(`storage location "${location.label}"`, root);
+ if (location.root) owned.push({ what: `storage location "${location.label}"`, root: await canonical(location.root) });
+ }
+ if (paths.monorepoRoot) owned.push({ what: "the Archilyzer checkout", root: await canonical(paths.monorepoRoot) });
+ // Inside an owned tree: the scan would read the archive's own files as
+ // recordings, and a move or a clean could change them under the library.
+ for (const { what, root } of owned) {
+ if (inside(root, lib)) return `The library directory is inside ${what} (${root}); choose a directory outside it.`;
}
- if (paths.monorepoRoot) {
- const root = await canonical(paths.monorepoRoot);
- if (inside(root, lib)) return refuse("the Archilyzer checkout", root);
+ // CONTAINING one (re-review F1): the library is read-only, so nothing is lost,
+ // but a scan of it would offer archive-owned media as recordings.
+ for (const { what, root } of owned) {
+ if (inside(lib, root)) return `The library directory contains ${what} (${root}); choose a directory that does not.`;
}
return null;
}
diff --git a/editor/app/channels/lib/prepareLocalArchiveChannel.test.ts b/editor/app/channels/lib/prepareLocalArchiveChannel.test.ts
@@ -52,7 +52,7 @@ test("corpus overlap is refused in either direction, including linked ancestors"
await symlink(f.paths.transcriptsDir,alias,"dir");
for (const directory of [f.root,f.paths.transcriptsDir,path.join(f.paths.transcriptsDir,"nested"),alias]) {
f.form.set("localDirectory",directory);
- await assert.rejects(prepareLocalArchiveChannel(f.paths,f.form),directory === f.root ? /must be separate/ : /must be separate|The library directory is inside the corpus/);
+ await assert.rejects(prepareLocalArchiveChannel(f.paths,f.form),/must be separate|The library directory (is inside|contains) the corpus/);
}
const absentCorpus = {...f.paths,transcriptsDir:path.join(alias,"not-created")};
f.form.set("localDirectory",f.paths.transcriptsDir);