stageRuntime method

ServiceDescriptor stageRuntime(
  1. ServiceDescriptor d
)

Copies d's runtime into runtimeDir and returns d rewritten to launch that private copy.

A dart pub global activate install runs as dart <snapshot>, where the snapshot lives in the per-SDK pub cache and is locked by Windows while the service runs — so updating omnyshell can't rewrite it, and a later uninstall+reinstall just re-pins the same stale bytes (the new version never takes effect). Staging a copy in a service-owned directory decouples the task from the pub cache: pub global activate is then free to rewrite its snapshot, and every (re)install refreshes this copy from the currently-running version.

Implementation

svc.ServiceDescriptor stageRuntime(svc.ServiceDescriptor d) {
  final rewritten = stagedDescriptor(d);
  if (identical(rewritten, d)) return d; // already staged: nothing to copy
  Directory(runtimeDir(d)).createSync(recursive: true);
  _copyOverwrite(_runtimeSource(d), stagedRuntimePath(d));
  return rewritten;
}