beginVersion method

Future<String> beginVersion()

Creates a private draft with zero HTML file copying.

Unchanged artifacts are referenced from immutable content-addressed storage via the route manifest. Only metadata is inherited.

Implementation

Future<String> beginVersion() async {
  await root.create(recursive: true);
  await _objectsDir.create(recursive: true);
  final version = 'v${DateTime.now().microsecondsSinceEpoch}_$pid';
  final draft = _versionDir(version);
  await draft.create(recursive: true);
  final active = await activeVersion;
  if (active != null) {
    final current = _versionDir(active);
    if (await current.exists()) {
      // Copy only metadata and manifests. NEVER copy HTML content files!
      await _copyManifestFiles(current, draft);
    }
  } else {
    // Import artifacts created by the pre-versioned store into .objects/
    await _importLegacyFiles(root, draft);
  }
  await File('${draft.path}${Platform.pathSeparator}.base_version')
      .writeAsString(active ?? '');
  return version;
}