MCPcopy
hub / github.com/ray-project/ray / _write_if_changed

Function _write_if_changed

python/ray/serve/_private/haproxy.py:159–169  ·  view source on GitHub ↗

Write content to path only if it differs from what's there.

(path: str, content: str)

Source from the content-addressed store, hash-verified

157
158
159def _write_if_changed(path: str, content: str) -> bool:
160 """Write content to path only if it differs from what's there."""
161 try:
162 with open(path) as f:
163 if f.read() == content:
164 return False
165 except FileNotFoundError:
166 pass
167 with open(path, "w") as f:
168 f.write(content)
169 return True
170
171
172def _tail_file(path: str, n_bytes: int = 4096) -> str:

Callers 1

Calls 3

openFunction · 0.85
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…