From 1db2229ad32849348e6899c64d7d81a75bfc3493 Mon Sep 17 00:00:00 2001 From: Huskydog9988 <39809509+Huskydog9988@users.noreply.github.com> Date: Wed, 7 May 2025 22:29:10 -0400 Subject: [PATCH] fix: edgecase where object hash isn't read --- server/internal/objects/fsBackend.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/server/internal/objects/fsBackend.ts b/server/internal/objects/fsBackend.ts index 05566227..1bc5aea2 100644 --- a/server/internal/objects/fsBackend.ts +++ b/server/internal/objects/fsBackend.ts @@ -132,19 +132,27 @@ export class FsObjectBackend extends ObjectBackend { // local variable to point to object const store = this.hashStore; + let hashResult = ""; - // read obj into hash - obj.pipe(hash); - await new Promise((r) => { + const objEnd = new Promise((r) => { obj.on("end", async function () { hash.end(); - await store.save(id, hash.read()); + hashResult = hash.read(); r(); }); }); + // read obj into hash + obj.pipe(hash); + await objEnd; - const result = await this.hashStore.get(id); - return result === null ? undefined : result; + console.log("object hash: ", hashResult); + + // if hash isn't a string somehow, mark as unknown hash + if (typeof hashResult !== "string") { + return undefined; + } + await store.save(id, hashResult); + return typeof hashResult; } }