From d8d177626089c78400ac8a0e0124d43ba6b5669d Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 22 Apr 2023 21:50:19 +0800 Subject: [PATCH] core: fix patch --- packages/hydrooj/src/commands/patch.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/hydrooj/src/commands/patch.ts b/packages/hydrooj/src/commands/patch.ts index f4e1f1608..20e0cdb1c 100644 --- a/packages/hydrooj/src/commands/patch.ts +++ b/packages/hydrooj/src/commands/patch.ts @@ -15,16 +15,17 @@ export function register(cli: CAC) { return; } logger.info('Patching %s', mod); - const res = await superagent.get(patch); + const res = await superagent.get(patch).responseType('arraybuffer'); logger.info('Downloaded patch'); for (let i = 0; i <= 100; i++) { - const fp = path.join(path.dirname(mod), `${mod}.${i}.patch`); + const fp = path.join(path.dirname(mod), `${path.basename(mod)}.${i}.patch`); if (fs.existsSync(fp)) continue; patch = fp; break; } - await fs.writeFile(patch, res.text); - child.execSync(`patch ${mod} -o ${mod} < ${patch}`); + await fs.writeFile(patch, res.body); + child.execSync(`patch ${mod} -o ${mod}.tmp < ${patch}`); + await fs.move(`${mod}.tmp`, mod); logger.info('Patched %s', mod); });