INNER CODE UNIT · TypeScript
verifyPatchFileTarget
totec448-spec/chat-on-steroids · src/main/codex/apply-patch/index.ts:70
async function verifyPatchFileTarget(path: string, allowMissing: boolean): Promise<void> {
try {
const metadata = await getMetadata(path);
if (!metadata.isFile) throw invalidInput('patch target is not a regular file');
if (metadata.size > MAX_PATCH_SOURCE_BYTES) {
throw invalidInput(`file is too large to patch safely: limit is ${MAX_PATCH_SOURCE_BYTES} bytes`);
}
} catch (error) {
if (allowMissing && errorCode(error) === 'ENOENT') return;
throw error;
}
}
const defaultPathResolver: PatchPathResolver = (spelledPath, cwd) => nodePath.resolve(cwd, spelledPath);
/** A move needs two distinct filesystem identities; otherwise write-then-remove deletes it. */
function sameResolvedPath(left: string, right: string): boolean {
const a = nodePath.resolve(left);