markRootActive method

void markRootActive(
  1. String packageConfigPath
)

Adds a file to the PUB_CACHE/active_roots/ dir indicating packageConfigPath is active.

Implementation

void markRootActive(String packageConfigPath) {
  final canonicalFileUri =
      p.toUri(p.canonicalize(packageConfigPath)).toString();

  final hash = hexEncode(sha256.convert(utf8.encode(canonicalFileUri)).bytes);

  final firstTwo = hash.substring(0, 2);
  final theRest = hash.substring(2);

  final dir = p.join(_activeRootsDir, firstTwo);
  ensureDir(dir);

  final filename = p.join(dir, theRest);
  writeTextFileIfDifferent(
    filename,
    '${jsonEncode({'package_config': canonicalFileUri})}\n',
  );
}