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 originRef = (await ChannelContentSource(rpc).manifest()).hash();
        final reanchored = record.copyWith(
          syncState: record.syncState.copyWith(
            baselineRef: originRef,
            clearError: true,
            status: SyncStatus.clean,
          ),
        );
        return _syncDirectory(
          reanchored,
          rpc,
          SyncDirection.pull,
          onProgress: onProgress,
        );
      case 'accept-local':
      default:
        // Re-anchor on the current origin so the next push is not a conflict,
        // then overwrite the origin with the local copy.
        final originRef = (await ChannelContentSource(rpc).manifest()).hash();
        final reanchored = record.copyWith(
          syncState: record.syncState.copyWith(
            baselineRef: originRef,
            clearError: true,
            status: SyncStatus.clean,
          ),
        );
        return _syncDirectory(
          reanchored,
          rpc,
          SyncDirection.push,
          onProgress: onProgress,
        );
    }
  });
  store.mounts[mountId] = outcome.record;
  await store.save();
  return outcome;
}