forgetProjectRoot method

Future<List<String>> forgetProjectRoot(
  1. String root
)

Deletes every index of every bundle at or inside the project root, whose directory may no longer exist, such as a removed worktree, with their writer.locks and the directories that leaves empty, as forget does for one bundle. Returns the canonical roots of the bundles whose indexes it deleted, sorted.

Indexes are kept per bundle root, so this finds a project's bundles by the root each index's writer.lock records, never by reading the project, which may be gone. root is canonicalized as forget canonicalizes a bundle's root: symbolic links in the part of it that still exists are resolved. Throws index-busy, and deletes nothing, while another operation indexes or forgets any of those bundles, while a current pointer cannot be removed, or while one holds the index of a bundle whose recorded root cannot be read, since it may be one of them: Windows refuses to read a held writer.lock, so there a bundle being indexed with no other configuration's lock to read makes the call busy, whichever project it belongs to. An index whose writer.lock records no root and is not held, as a writer interrupted while writing it can leave, cannot be told apart from another project's: neither this call nor prune deletes it while its configuration is the store's, and forget of its bundle does. A blank root, which would name the working directory, is an ArgumentError.

Implementation

Future<List<String>> forgetProjectRoot(String root) => _admit(() async {
  if (root.trim().isEmpty) {
    throw ArgumentError.value(root, 'root', 'must not be blank');
  }
  final project = await _canonicalPath(root);
  if (project == null) return const <String>[];
  final indexes = Directory(await _bundlesDirectory());
  if (!await indexes.exists()) return const <String>[];
  final forgotten = <String, Directory>{};
  for (final entry in await indexes.list(followLinks: false).toList()) {
    if (entry is! Directory || !_key.hasMatch(p.basename(entry.path))) {
      continue;
    }
    final bundle = await _recordedRoot(entry);
    if (bundle != null &&
        (p.equals(bundle, project) || p.isWithin(project, bundle))) {
      forgotten[bundle] = entry;
    }
  }
  await _forget(forgotten.values.toList());
  return forgotten.keys.toList()..sort();
});