Small changes
This commit is contained in:
parent
7293c58a71
commit
b52c09fecc
1 changed files with 69 additions and 292 deletions
|
|
@ -8,18 +8,12 @@
|
|||
export const CONFLICT_PATH_REGEX =
|
||||
/(?:^|\/)conflict-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}-[^/]*$/u;
|
||||
|
||||
// Safe segment length for common filesystems (ext4 / NTFS / APFS all cap
|
||||
// at 255 bytes). `conflict-<36-char-uuid>-` adds 46 bytes; reserve a few
|
||||
// extra bytes for a future prefix bump and leave room for multi-byte UTF-8
|
||||
// characters in the original name.
|
||||
|
||||
const CONFLICT_PREFIX_LEN = "conflict-".length + 36 + 1;
|
||||
const MAX_SEGMENT_BYTES = 255;
|
||||
const MAX_ORIGINAL_BYTES = MAX_SEGMENT_BYTES - CONFLICT_PREFIX_LEN - 4;
|
||||
|
||||
export function buildConflictFileName(fileName: string): string {
|
||||
// Truncate the original name if keeping it whole would bust the
|
||||
// filesystem's segment-length cap. Preserve the trailing extension
|
||||
// so the file is still recognizable / openable.
|
||||
const safeName = truncateFileNameToByteLimit(fileName, MAX_ORIGINAL_BYTES);
|
||||
return `conflict-${crypto.randomUUID()}-${safeName}`;
|
||||
}
|
||||
|
|
@ -40,8 +34,6 @@ function truncateFileNameToByteLimit(
|
|||
const extensionBytes = encoder.encode(extension).byteLength;
|
||||
const stemBudget = Math.max(0, maxBytes - extensionBytes);
|
||||
|
||||
// Walk the stem by grapheme cluster so we never split an emoji sequence
|
||||
// (e.g. ZWJ families, skin-tone modifiers) or a base+combining-mark pair.
|
||||
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
||||
let truncatedStem = "";
|
||||
let usedBytes = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue