INNER CODE UNIT · TypeScript
applyHunksToFiles
totec448-spec/chat-on-steroids · src/main/codex/apply-patch/index.ts:233
async function applyHunksToFiles(
hunks: readonly Hunk[],
updateFileMode: ApplyPatchFileUpdateMode,
cwd: string,
resolvePath: PatchPathResolver,
delta: AppliedPatchDelta
): Promise<AffectedPaths> {
if (hunks.length === 0) throw new Error('No files were modified.');
const added: string[] = [];
const modified: string[] = [];
const deleted: string[] = [];
// A failed write can still have modified the target before surfacing an error (for example by
// truncating before ENOSPC), so the accumulated delta is no longer exact when a write fails.
const tryWrite = async <T>(work: Promise<T>): Promise<T> => {
try {
return await work;