Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix: report ambiguous filenames before syncing a folder
Afloat74f75e606369
diff --git a/electron/cloud-sync-engine.mjs b/electron/cloud-sync-engine.mjsindex 4607b7dfef..16e8e71a4f 100644--- a/electron/cloud-sync-engine.mjs+++ b/electron/cloud-sync-engine.mjs@@ -4,9 +4,9 @@import { createHash } from "node:crypto";import fs from "node:fs";import path from "node:path";-import { RESERVE_BYTES, clashPath, neverFromCloud, validWirePath, windowsProblem } from "./cloud-sync-rules.mjs";+import { RESERVE_BYTES, clashPath, foldKey, neverFromCloud, validWirePath, windowsProblem } from "./cloud-sync-rules.mjs";import { planOutputs, planShare } from "./cloud-sync-plan.mjs";-import { scanPc, sha256File } from "./cloud-sync-scan.mjs";+import { caseInsensitive, scanPc, sha256File } from "./cloud-sync-scan.mjs";import { SyncAuthError } from "./cloud-sync-client.mjs";import { CloudAsleepError } from "./cloud-power.mjs";@@ -114,6 +114,20 @@ export async function fetchOutputs({ client, state, folder, local, platform = prconst { entries: pc, temps } = await scanPc(local, base, { now });for (const temp of temps) if (now() - temp.mtimeMs > TEMP_STALE_MS) fs.rmSync(temp.file, { force: true });const listed = (await client.files(folder.id)).filter((file) => validWirePath(file.path) && !neverFromCloud(file.path) && !(platform === "win32" && windowsProblem(file.path)));+ if (caseInsensitive(local, platform)) {+ const names = new Map();+ for (const file of listed) {+ const parts = file.path.split("/");+ for (let length = 1; length <= parts.length; length++) {+ const name = parts.slice(0, length).join("/"), key = foldKey(name);+ const previous = names.get(key);+ if (previous !== undefined && previous !== name) {+ throw new Error(`${JSON.stringify(previous)} and ${JSON.stringify(name)} have the same name on this computer. Rename one on My Cloud before syncing.`);+ }+ names.set(key, name);+ }+ }+ }const cloud = new Map(listed.map((file) => [file.path, file]));const { downloads, records } = planOutputs({ base, pc, cloud });const ctx = { client, state, folder, local, pc, cloud, now, trashItem, markDownloaded, freeBytes, result };diff --git a/electron/cloud-sync-name-collisions.node-test.mjs b/electron/cloud-sync-name-collisions.node-test.mjsnew file mode 100644index 0000000000..70eca6a52a--- /dev/null+++ b/electron/cloud-sync-name-collisions.node-test.mjs@@ -0,0 +1,69 @@+import assert from "node:assert/strict";+import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import test from "node:test";+import { fetchOutputs, newReport, shareFolder } from "./cloud-sync-engine.mjs";+import { scanPc, caseInsensitive } from "./cloud-sync-scan.mjs";+import { openSyncState } from "./cloud-sync-state.mjs";+import { fakeCloud } from "./fixtures/cloud-sync-fake-cloud.mjs";++function setup(t) {+ const home = mkdtempSync(join(tmpdir(), "omb-sync-names-"));+ const local = join(home, "Local");+ mkdirSync(local);+ const state = openSyncState(join(home, "state.db"));+ t.after(() => { state.close(); rmSync(home, { recursive: true, force: true }); });+ const cloud = fakeCloud();+ const folder = cloud.addFolder({ id: "folder", kind: "pc", cloudPath: "/cloud" });+ const ctx = { local, state, client: cloud.client, folder, report: newReport(), now: () => Date.now() + 60_000 };+ return { ...ctx, cloud };+}++for (const directory of [false, true]) test(`refuses two ${directory ? "directories" : "files"} with the same normalized sync name`, async (t) => {+ const ctx = setup(t);+ const names = ["café", "cafe\u0301"];+ for (const [index, name] of names.entries()) {+ if (directory) mkdirSync(join(ctx.local, name), { recursive: true });+ writeFileSync(join(ctx.local, name, ...(directory ? ["note.txt"] : [])), `copy ${index}`);+ }+ if (readdirSync(ctx.local).length !== 2) { t.skip("this filesystem already aliases Unicode-normalized names"); return; }+ ctx.cloud.put(ctx.folder.id, "existing.txt", "keep");+ await assert.rejects(shareFolder(ctx), /same.*name|name.*conflict/i);+ assert.equal(ctx.cloud.get(ctx.folder.id, "existing.txt"), "keep");+ assert.equal(ctx.cloud.calls.length, 0);+ assert.equal(ctx.state.base(ctx.folder.id).size, 0);+});++test("a single decomposed filename still uploads using its normalized wire name", async (t) => {+ const ctx = setup(t);+ writeFileSync(join(ctx.local, "cafe\u0301.txt"), "coffee");+ await shareFolder(ctx);+ assert.equal(ctx.cloud.get(ctx.folder.id, "café.txt"), "coffee");+});++for (const names of [["Report.txt", "report.txt"], ["Data", "data/result.txt"], ["Docs/a.txt", "docs/b.txt"]]) test(`refuses case-aliasing Cloud paths ${names.join(" and ")} on Windows`, async (t) => {+ const ctx = setup(t);+ ctx.cloud.put(ctx.folder.id, names[0], "first");+ ctx.cloud.put(ctx.folder.id, names[1], "second");+ const downloaded = [];+ await assert.rejects(fetchOutputs({ ...ctx, platform: "win32", freeBytes: () => 100 * 1024 ** 3,+ markDownloaded: async file => { downloaded.push(file); }, trashItem: async () => { throw new Error("must not trash"); },+ }), /same.*name|name.*conflict/i);+ assert.deepEqual(downloaded, []);+ assert.deepEqual(readdirSync(ctx.local), []);+ assert.equal(ctx.state.base(ctx.folder.id).size, 0);+});++test("keeps distinct case-sensitive Cloud filenames on a filesystem that supports them", async (t) => {+ const ctx = setup(t);+ if (caseInsensitive(ctx.local)) { t.skip("requires a case-sensitive filesystem"); return; }+ ctx.cloud.put(ctx.folder.id, "Report.txt", "first");+ ctx.cloud.put(ctx.folder.id, "report.txt", "second");+ await fetchOutputs({ ...ctx, platform: "linux", freeBytes: () => 100 * 1024 ** 3,+ markDownloaded: async () => {}, trashItem: async () => { throw new Error("must not trash"); },+ });+ assert.equal(readFileSync(join(ctx.local, "Report.txt"), "utf8"), "first");+ assert.equal(readFileSync(join(ctx.local, "report.txt"), "utf8"), "second");+ assert.equal((await scanPc(ctx.local, ctx.state.base(ctx.folder.id))).entries.size, 2);+});diff --git a/electron/cloud-sync-scan.mjs b/electron/cloud-sync-scan.mjsindex 8c6893a76a..859bc5c2a0 100644--- a/electron/cloud-sync-scan.mjs+++ b/electron/cloud-sync-scan.mjs@@ -22,6 +22,7 @@ function* walkPc(root, wire = "", real = []) {throw error;}const names = entries.map((entry) => entry.name);+ const syncNames = new Map();for (const entry of entries.sort((a, b) => (a.name < b.name ? -1 : 1))) {const file = join(root, ...real, entry.name);if (/\.omb-sync-[0-9a-f]+$/.test(entry.name)) {@@ -32,6 +33,11 @@ function* walkPc(root, wire = "", real = []) {const name = entry.name.normalize("NFC");const path = wire ? `${wire}/${name}` : name;if (skipped(entry.name, entry.isDirectory()) || !validWirePath(path)) continue;+ const previous = syncNames.get(name);+ if (previous !== undefined && previous !== entry.name) {+ throw new Error(`${JSON.stringify(previous)} and ${JSON.stringify(entry.name)} have the same sync name. Rename one before syncing.`);+ }+ syncNames.set(name, entry.name);if (entry.isDirectory()) { yield* walkPc(root, path, [...real, entry.name]); continue; }if (entry.isSymbolicLink()) { yield { path, kept: true, dir: statSync(file, { throwIfNoEntry: false })?.isDirectory() ?? false }; continue; }if (!entry.isFile()) continue;