return paths
This commit is contained in:
parent
c9cf3239db
commit
aecbcd1d2c
12 changed files with 20 additions and 136 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert";
|
||||
import { buildConflictFileName, isConflictPath } from "./conflict-path";
|
||||
import { buildConflictFileName, CONFLICT_PATH_REGEX } from "./conflict-path";
|
||||
|
||||
describe("buildConflictFileName", () => {
|
||||
it("truncates to the filesystem byte limit while preserving the extension", () => {
|
||||
|
|
@ -59,20 +59,20 @@ describe("buildConflictFileName", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("isConflictPath", () => {
|
||||
describe("CONFLICT_PATH_REGEX", () => {
|
||||
it("does not misclassify user-authored names that start with `conflict-`", () => {
|
||||
assert.strictEqual(isConflictPath("conflict-resolution.md"), false);
|
||||
assert.strictEqual(CONFLICT_PATH_REGEX.test("conflict-resolution.md"), false);
|
||||
});
|
||||
|
||||
it("only inspects the final path segment", () => {
|
||||
assert.strictEqual(
|
||||
isConflictPath(
|
||||
CONFLICT_PATH_REGEX.test(
|
||||
"conflict-12345678-1234-1234-1234-123456789abc-x/note.md"
|
||||
),
|
||||
false
|
||||
);
|
||||
assert.strictEqual(
|
||||
isConflictPath(
|
||||
CONFLICT_PATH_REGEX.test(
|
||||
"a/b/conflict-12345678-1234-1234-1234-123456789abc-note.md"
|
||||
),
|
||||
true
|
||||
|
|
@ -80,6 +80,6 @@ describe("isConflictPath", () => {
|
|||
});
|
||||
|
||||
it("round-trips with buildConflictFileName", () => {
|
||||
assert.strictEqual(isConflictPath(buildConflictFileName("note.md")), true);
|
||||
assert.strictEqual(CONFLICT_PATH_REGEX.test(buildConflictFileName("note.md")), true);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import type { RelativePath } from "./types";
|
||||
|
||||
// Local-only files displaced by `FileOperations.ensureClearPath` are named
|
||||
// `conflict-<uuid>-<originalName>`. The UUID is a full RFC-4122 v4 value so
|
||||
// a user-authored filename that happens to start with `conflict-` doesn't
|
||||
|
|
@ -55,14 +53,3 @@ function truncateFileNameToByteLimit(
|
|||
}
|
||||
return truncatedStem + extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is `path`'s final segment a conflict-displaced filename?
|
||||
*
|
||||
* Any sync code that would otherwise create/update/delete/sync the path
|
||||
* should short-circuit when this returns true: conflict-displaced files are
|
||||
* strictly local and must stay invisible to the server.
|
||||
*/
|
||||
export function isConflictPath(path: RelativePath): boolean {
|
||||
return CONFLICT_PATH_REGEX.test(path);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue