feat(sync): finish state file implementation
Some checks failed
Actions / Build and Push Documentation (push) Failing after 36s
Some checks failed
Actions / Build and Push Documentation (push) Failing after 36s
This commit is contained in:
parent
872ea12b3d
commit
e8873f3ce8
1 changed files with 12 additions and 26 deletions
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue