Skip to content

Commit

Permalink
fix: Should also verify non sha1 output
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Dec 30, 2023
1 parent 524c044 commit 1ae3c59
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/installer/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export async function diagnoseInstall(installProfile: InstallProfile, minecraftL
}))
for (const proc of processors) {
if (proc.outputs) {
for (const file in proc.outputs) {
for (const [file, checksum] of Object.entries(proc.outputs)) {
const issue = await diagnoseFile({
role: 'processor',
file,
expectedChecksum: proc.outputs[file].replace(/'/g, ''),
expectedChecksum: checksum.replace(/'/g, ''),
hint: 'Re-install this installer profile!',
})
if (issue) {
Expand Down
12 changes: 6 additions & 6 deletions packages/installer/forge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,17 @@ type RequiredVersion = {
installer?: {
sha1?: string
/**
* The url path to concat with forge maven
*/
* The url path to concat with forge maven
*/
path: string
}
/**
* The minecraft version
*/
* The minecraft version
*/
mcversion: string
/**
* The forge version (without minecraft version)
*/
* The forge version (without minecraft version)
*/
version: string
}

Expand Down
30 changes: 24 additions & 6 deletions packages/installer/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,29 @@ export function resolveProcessors(side: 'client' | 'server', installProfile: Ins
server: dirname(variables.INSTALLER.server),
}
}
const processors = (installProfile.processors || []).map((proc) => ({
...proc,
args: proc.args.map(normalizePath).map(normalizeVariable),
outputs: proc.outputs

const resolveOutputs = (proc: PostProcessor, args: string[]) => {
const original = proc.outputs
? Object.entries(proc.outputs).map(([k, v]) => ({ [normalizeVariable(k)]: normalizeVariable(v) })).reduce((a, b) => Object.assign(a, b), {})
: undefined,
})).filter((proc) => proc.sides ? proc.sides.indexOf(side) !== -1 : true)
: {}
for (const [key, val] of Object.entries(original)) {
original[key] = val.replace(/'/g, '')
}
const outputIndex = args.indexOf('--output')
const outputFile = outputIndex !== -1 ? args[outputIndex + 1] : undefined
if (outputFile && !original[outputFile]) {
original[outputFile] = ''
}
return original
}
const processors = (installProfile.processors || []).map((proc) => {
const args = proc.args.map(normalizePath).map(normalizeVariable)
return {
...proc,
args,
outputs: resolveOutputs(proc, args),
}
}).filter((proc) => proc.sides ? proc.sides.indexOf(side) !== -1 : true)
return processors
}

Expand Down Expand Up @@ -248,6 +264,8 @@ export class PostProcessingTask extends AbortableTask<void> {
protected async isInvalid(outputs: Required<PostProcessor>['outputs']) {
for (const [file, expect] of Object.entries(outputs)) {
const sha1 = await checksum(file, 'sha1').catch((e) => '')
if (!sha1) return true // if file not exist, the file is not generated
if (!expect) return false // if expect is empty, we just need file exists
const expected = expect.replace(/'/g, '')
if (expected !== sha1) {
return true
Expand Down

0 comments on commit 1ae3c59

Please sign in to comment.