An album whose folder cannot be made no longer stops the backup (closes #197)
check / check (push) Waiting to run
check / check (push) Waiting to run
Each album's folder, links and JSON are written inside one try. A failure prints `FAILED album <name>: <reason>`, lists the album's ID in the new `failedAlbums` of the result and of `--json`, and makes `quak backup` exit 1; the other albums and `failures.json` are still written. An album whose folder would have another album's JSON name, ignoring case, gets its ID. A name over 255 bytes (250 for a folder, which leaves room for `.json`) gets the ID and is cut short between two characters by `shortenToBytes` in `src/filename.ts`. A link's ID goes right before its extension. Apart from its call to `uniqueNames`, the album loop is only indented into the try. Model: opus-5-5
This commit was merged in pull request #204.
This commit is contained in:
@@ -14,7 +14,11 @@
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { safeExtension, sanitizeFileName } from "../../src/filename.js";
|
||||
import {
|
||||
safeExtension,
|
||||
sanitizeFileName,
|
||||
shortenToBytes,
|
||||
} from "../../src/filename.js";
|
||||
|
||||
const FALLBACK = "file-42";
|
||||
|
||||
@@ -91,3 +95,26 @@ describe("safeExtension", () => {
|
||||
expect(safeExtension("x.jpg\0")).toBe(".bin");
|
||||
});
|
||||
});
|
||||
|
||||
describe("shortenToBytes", () => {
|
||||
it("returns a name that fits unchanged", () => {
|
||||
expect(shortenToBytes("beach", 5)).toBe("beach");
|
||||
expect(shortenToBytes("café", 5)).toBe("café");
|
||||
expect(shortenToBytes("", 0)).toBe("");
|
||||
});
|
||||
|
||||
it("cuts a name to the number of bytes given", () => {
|
||||
expect(shortenToBytes("L".repeat(300), 255)).toBe("L".repeat(255));
|
||||
});
|
||||
|
||||
// In UTF-8 "é" takes two bytes and an emoji four, which a JavaScript
|
||||
// string holds as two halves.
|
||||
it("cuts between two characters, never inside one", () => {
|
||||
expect(shortenToBytes("ééé", 5)).toBe("éé");
|
||||
expect(shortenToBytes("a\u{1F600}b", 4)).toBe("a");
|
||||
expect(shortenToBytes("a\u{1F600}b", 5)).toBe("a\u{1F600}");
|
||||
expect(Buffer.byteLength(shortenToBytes("é".repeat(200), 255))).toBe(
|
||||
254,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user