mirror of
https://github.com/unraid/api.git
synced 2026-01-01 06:01:18 -06:00
fix: patch-utils unused
This commit is contained in:
@@ -1,20 +0,0 @@
|
|||||||
import { readFile, writeFile } from 'fs/promises';
|
|
||||||
import { applyPatch, parsePatch, reversePatch } from 'diff';
|
|
||||||
|
|
||||||
export async function rollbackPatch(targetFile: string, patch: string): Promise<void> {
|
|
||||||
const currentContent = await readFile(targetFile, 'utf8');
|
|
||||||
const parsedPatch = parsePatch(patch)[0];
|
|
||||||
|
|
||||||
if (!parsedPatch || !parsedPatch.hunks || parsedPatch.hunks.length === 0) {
|
|
||||||
throw new Error('Invalid or empty patch content');
|
|
||||||
}
|
|
||||||
|
|
||||||
const reversedPatch = reversePatch(parsedPatch);
|
|
||||||
const results = applyPatch(currentContent, reversedPatch);
|
|
||||||
|
|
||||||
if (results === false) {
|
|
||||||
throw new Error(`Failed to rollback patch from ${targetFile}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await writeFile(targetFile, results);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user