snapshotDirectories method

Future<void> snapshotDirectories(
  1. List<String> rels
)

Snapshots each folder whole. A folder that doesn't exist yet is recorded as absent, so restoring removes it if the run created it. Folders already snapshotted in this run keep their first snapshot.

Implementation

Future<void> snapshotDirectories(List<String> rels) async {
  final index = _readSnapshotIndex();
  final known =
      index.map((e) => e.startsWith('!') ? e.substring(1) : e).toSet();
  for (final rel in rels) {
    if (known.contains(rel)) continue;
    final dir = Directory(p.join(projectDir, rel));
    if (dir.existsSync()) {
      await WorkspaceManager.sync(
          dir, Directory(p.join(_snapshotRoot.path, rel)));
      index.add(rel);
    } else {
      index.add('!$rel');
    }
  }
  await _snapshotIndex.parent.create(recursive: true);
  await _snapshotIndex.writeAsString(index.join('\n'));
}