Skip to content

Commit d4a3c63

Browse files
committed
Update
1 parent 5d0627d commit d4a3c63

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.13-slim
22

3-
RUN apt-get update && apt-get install -y --no-install-recommends git jq && rm -rf /var/lib/apt/lists/*
3+
RUN apt-get update && apt-get install -y --no-install-recommends git jq patch && rm -rf /var/lib/apt/lists/*
44

55
WORKDIR /app
66
COPY requirements.txt .

make_accessible.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44
import tempfile
55
from openai import OpenAI
6-
import patch
6+
import subprocess
77

88
INJECTION_PATTERNS = [
99
r"ignore.*instructions", r"disregard.*above", r"assistant.*role", r"user.*role",
@@ -122,21 +122,39 @@ def main():
122122

123123

124124
# Write the filtered diff to a temporary file
125-
with tempfile.NamedTemporaryFile(mode='w+', delete=False) as tmp_patch:
125+
with tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix=".patch") as tmp_patch:
126126
tmp_patch.write(filtered_diff)
127127
tmp_patch_path = tmp_patch.name
128128

129-
# Apply the patch
130-
pset = patch.fromfile(tmp_patch_path)
131-
if not pset:
132-
print("::error::Failed to parse generated patch.", file=sys.stderr)
129+
# Apply the patch using the patch command-line utility
130+
swift_file_abspath = os.path.abspath(swift_file)
131+
root_dir = os.path.dirname(swift_file_abspath)
132+
133+
patch_command = ['patch', '-p0', '--input', tmp_patch_path]
134+
print(f"Running patch command: {' '.join(patch_command)} in directory {root_dir}")
135+
136+
try:
137+
result = subprocess.run(
138+
patch_command,
139+
cwd=root_dir,
140+
check=True,
141+
capture_output=True,
142+
text=True
143+
)
144+
print("Patch applied successfully using command!")
145+
except subprocess.CalledProcessError as e:
146+
print(f"::error::Failed to apply patch using command: {' '.join(patch_command)}", file=sys.stderr)
147+
print(f"::error::Return code: {e.returncode}", file=sys.stderr)
148+
print(f"::error::stdout: {e.stdout}", file=sys.stderr)
149+
print(f"::error::stderr: {e.stderr}", file=sys.stderr)
150+
print("::error::Patch content was:", file=sys.stderr)
151+
print(filtered_diff, file=sys.stderr)
133152
sys.exit(1)
134-
root_dir = os.path.dirname(os.path.abspath(swift_file))
135-
if pset.apply(root=root_dir):
136-
print("Patch applied successfully!")
137-
else:
138-
print("::error::Failed to apply patch.", file=sys.stderr)
153+
except FileNotFoundError:
154+
print("::error::'patch' command not found. Is it installed in the container?", file=sys.stderr)
139155
sys.exit(1)
156+
finally:
157+
os.remove(tmp_patch_path)
140158

141159
if __name__ == "__main__":
142160
main()

0 commit comments

Comments
 (0)