resolve method

Future<SyncOutcome> resolve(
  1. String mountId, {
  2. required String strategy,
  3. DriveProgress? onProgress,
})

Resolves a conflict on mountId. strategy is accept-local, accept-origin, or reclone.

Implementation

Future<SyncOutcome> resolve(
  String mountId, {
  required String strategy,
  DriveProgress? onProgress,
}) async {
  final record = require(mountId);
  final outcome = await _withSession(record, (rpc) async {
    if (record.isGit) {
      // Git: accepting the origin re-pulls; accepting local re-attempts push.
      final dir = strategy == 'accept-local'
          ? SyncDirection.push
          : SyncDirection.pull;
      return _syncGit(record, rpc, dir, onProgress: onProgress);
    }
    switch (strategy) {
      case 'accept-origin':
      case 'reclone':
        // Re-anchor on the origin and pull it down over the local copy.
        final originManifest = await ChannelContentSource(rpc).manifest();
        final reanchored = record.copyWith(
          syncState: record.syncState.copyWith(
            baselineRef: originManifest.hash(),
            clearError: true,
            status: SyncStatus.clean,
          ),
        );
        // After the pull local matches the origin: snapshot it as the baseline.
        return _attachBaseline(
          await _syncDirectory(
            reanchored,
            rpc,
            SyncDirection.pull,
            onProgress: onProgress,
          ),
          originManifest,
        );
      case 'accept-local':
      default:
        return _pushLocalAuthoritative(record, rpc, onProgress: onProgress);
    }
  });
  store.mounts[mountId] = outcome.record;
  await store.save();
  return outcome;
}