Remove the content cache's handling of an earlier version's live-photo ZIP (closes #151)
check / check (push) Failing after 44s
check / check (push) Failing after 44s
quak is pre-1.0 and keeps no handling of old data. The content cache no longer recognises or removes a live photo that an earlier quak version cached as one ZIP. A live-photo download no longer removes what was at its destination before renaming the image and video into place; the rename already replaces it. The README sentences and the tests about that old ZIP are gone. The two removed tests that also covered current behaviour are replaced by tests with no ZIP: the cache re-fetching a live photo recorded with no video, and the library telling the cache which files are live photos when it opens. Model: opus-5-5
This commit was merged in pull request #152.
This commit is contained in:
@@ -361,8 +361,8 @@ const openPart = async (
|
||||
// written unpacked: each part is named `destination` with the extension
|
||||
// replaced by its own entry's, and the two must differ ignoring case. When the
|
||||
// file records a hash, `<imageHash>:<videoHash>` must match it, each over that
|
||||
// part's own bytes. Only then is whatever was at `destination` removed and the
|
||||
// image, then the video, renamed into place; on any failure neither is stored.
|
||||
// part's own bytes. Only then are the image, then the video, renamed into
|
||||
// place; on any failure neither is stored.
|
||||
//
|
||||
// The ZIP is chosen by its uploader and may expand enormously, so each part is
|
||||
// written as it decompresses and never held, and the ZIP is refused once the
|
||||
@@ -486,7 +486,6 @@ const decryptLivePhoto = async (
|
||||
await part.handle.sync();
|
||||
await part.handle.close();
|
||||
}
|
||||
await rm(destination, { force: true });
|
||||
await rename(image.tmpPath, path);
|
||||
try {
|
||||
await rename(video.tmpPath, videoPath);
|
||||
@@ -570,8 +569,7 @@ const fetchAndDecrypt = async (
|
||||
}, api.getRetryOptions());
|
||||
|
||||
// Write `file`'s original to `outPath`. A live photo is written as its image
|
||||
// and its video beside `outPath` instead, and whatever was at `outPath` is
|
||||
// removed (see `decryptLivePhoto`).
|
||||
// and its video beside `outPath` instead (see `decryptLivePhoto`).
|
||||
export const downloadFile = async (
|
||||
api: ApiClient,
|
||||
file: EnteFile,
|
||||
|
||||
+8
-38
@@ -29,14 +29,7 @@
|
||||
// the cache does not count as saved there, but is copied there rather than
|
||||
// fetched again.
|
||||
|
||||
import {
|
||||
closeSync,
|
||||
existsSync,
|
||||
openSync,
|
||||
readFileSync,
|
||||
readSync,
|
||||
statSync,
|
||||
} from "node:fs";
|
||||
import { existsSync, readFileSync, statSync } from "node:fs";
|
||||
import {
|
||||
chmod,
|
||||
copyFile,
|
||||
@@ -281,25 +274,6 @@ const fileSize = (path: string): number | undefined => {
|
||||
const hasContent = (path: string | undefined): boolean =>
|
||||
path !== undefined && (fileSize(path) ?? 0) > 0;
|
||||
|
||||
// Whether the file at `path` begins as a ZIP does, with `PK\x03\x04`. False
|
||||
// when it cannot be read.
|
||||
const isZip = (path: string): boolean => {
|
||||
try {
|
||||
const fd = openSync(path, "r");
|
||||
try {
|
||||
const head = Buffer.alloc(4);
|
||||
return (
|
||||
readSync(fd, head, 0, 4, 0) === 4 &&
|
||||
head.toString("latin1") === "PK\x03\x04"
|
||||
);
|
||||
} finally {
|
||||
closeSync(fd);
|
||||
}
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// A live photo's image and video are named with the extensions from inside its
|
||||
// ZIP, so their names alone do not say which is which. Wherever the cache or a
|
||||
// save path stores one, a JSON file of this name beside them names both.
|
||||
@@ -713,8 +687,10 @@ export class ContentCache implements PhotoContent, ThumbnailsAPI {
|
||||
await this.touch(cached.path);
|
||||
return { ...cached, bytes: size, cached: true };
|
||||
}
|
||||
// A recorded file that has since gone, or a live photo an earlier
|
||||
// version stored as one ZIP, re-fetches below.
|
||||
// A recorded file that has since gone re-fetches below. So does a
|
||||
// live photo recorded with no video: the cache opened before the
|
||||
// library's records said it is a live photo, while its image and
|
||||
// video had no JSON file beside them yet.
|
||||
known.delete(fileID);
|
||||
}
|
||||
|
||||
@@ -983,20 +959,14 @@ export class ContentCache implements PhotoContent, ThumbnailsAPI {
|
||||
if (id === undefined || !existsSync(path)) continue;
|
||||
// A live photo's image and video are one entry, as the JSON file
|
||||
// beside them names them. A live photo's file with no such JSON
|
||||
// file is not its original. If it is a ZIP, it is the one an
|
||||
// earlier version stored under the image's name, and is removed.
|
||||
// Any other is left alone: another process may have just stored
|
||||
// it and not yet written the JSON file.
|
||||
// file is not its original and is left alone: another process may
|
||||
// have just stored it and not yet written the JSON file.
|
||||
const livePhoto = names.has(livePhotoJSONName(String(id)))
|
||||
? readLivePhotoJSON(dir, String(id))
|
||||
: undefined;
|
||||
if (livePhoto !== undefined) {
|
||||
into.set(id, livePhoto);
|
||||
} else if (isLivePhoto(id)) {
|
||||
if (isZip(path)) {
|
||||
await rm(path, { force: true }).catch(() => undefined);
|
||||
}
|
||||
} else {
|
||||
} else if (!isLivePhoto(id)) {
|
||||
into.set(id, { path });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user