diff --git a/packages/sync/src/sync.ts b/packages/sync/src/sync.ts index 9efdd52..c4c9da8 100644 --- a/packages/sync/src/sync.ts +++ b/packages/sync/src/sync.ts @@ -38,22 +38,19 @@ function getSaveLocation( } } -async function writeStateFile( - packwiz: Packwiz, - hashes: { [fileName: string]: HashInfo }, -) { +async function writeStateFile(packwiz: Packwiz) { const stateFile = packwiz.index.location.parent.join(".packwizjs-state.json"); const state: State = { stateVersion: 1, currentVersion: packwiz.version, - hashes: hashes, + hashes: {}, }; - // for (const file of packwiz.index.files) { - // state.hashes[packwiz.index.location.diff(file.file).join("/")] = { - // hashFormat: file.hashFormat, - // hash: file.hash, - // }; - // } + for (const file of packwiz.index.files) { + state.hashes[packwiz.index.location.diff(file.file).join("/")] = { + hashFormat: file.hashFormat, + hash: file.hash, + }; + } const saveLocation = getSaveLocation(stateFile, packwiz.index); await write(saveLocation.toString(), JSON.stringify(state, null)); } @@ -201,15 +198,9 @@ export async function iteratePackwizIndex( } if (state) { - let stateHash: HashInfo | undefined; - // TODO: implement hash checking for files downloaded via metafile providers - if (!file.metafile) { - stateHash = - state.hashes[ - packwiz.index.location.diff(file.file).join("/") - ]; - } - if (stateHash?.hash && stateHash.hash === hash) { + const stateHash = + state.hashes[packwiz.index.location.diff(file.file).join("/")]; + if (stateHash?.hash && stateHash.hash === file.hash) { console.log( `Skipping already downloaded file ${file.file.toString()}`, ); @@ -219,11 +210,6 @@ export async function iteratePackwizIndex( } else { await downloadFile(hash, hashFormat, url, saveLocation); } - - hashes[packwiz.index.location.diff(file.file).join("/")] = { - hashFormat: hashFormat, - hash: hash, - }; } catch (error) { console.error(`Error downloading file: ${error}`); reject(error); @@ -236,5 +222,5 @@ export async function iteratePackwizIndex( } } downloadNextFile(); - }).then(() => writeStateFile(packwiz, hashes)); + }).then(() => writeStateFile(packwiz)); }