MCPcopy Index your code
hub / github.com/cft0808/edict / _sync_script_symlink

Function _sync_script_symlink

scripts/sync_agent_config.py:225–255  ·  view source on GitHub ↗

Create a symlink dst_file → src_file (resolved). Using symlinks instead of physical copies ensures that ``__file__`` in each script always resolves back to the project ``scripts/`` directory, so relative-path computations like ``Path(__file__).resolve().parent.parent`` point to the

(src_file: pathlib.Path, dst_file: pathlib.Path)

Source from the content-addressed store, hash-verified

223}
224
225def _sync_script_symlink(src_file: pathlib.Path, dst_file: pathlib.Path) -> bool:
226 """Create a symlink dst_file → src_file (resolved).
227
228 Using symlinks instead of physical copies ensures that ``__file__`` in
229 each script always resolves back to the project ``scripts/`` directory,
230 so relative-path computations like ``Path(__file__).resolve().parent.parent``
231 point to the correct project root regardless of which workspace runs the
232 script. (Fixes #56 — kanban data-path split)
233
234 Returns True if the link was (re-)created, False if already up-to-date.
235 """
236 src_resolved = src_file.resolve()
237 # Guard: skip if dst resolves to the same real path as src.
238 # This happens when ws_scripts is itself a directory-level symlink pointing
239 # to the project scripts/ dir (created by install.sh link_resources).
240 # Without this check the function would unlink the real source file and
241 # then create a self-referential symlink (foo.py -> foo.py).
242 try:
243 dst_resolved = dst_file.resolve()
244 except OSError:
245 dst_resolved = None
246 if dst_resolved == src_resolved:
247 return False
248 # Already a correct symlink?
249 if dst_file.is_symlink() and dst_resolved == src_resolved:
250 return False
251 # Remove stale file / old physical copy / broken symlink
252 if dst_file.exists() or dst_file.is_symlink():
253 dst_file.unlink()
254 os.symlink(src_resolved, dst_file)
255 return True
256
257
258def sync_scripts_to_workspaces():

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected