uploadPath function

Future<TransferResult> uploadPath({
  1. required ClientRuntime client,
  2. required String nodeId,
  3. required String localPath,
  4. required String remoteDir,
  5. int gzipLevel = kDefaultGzipLevel,
  6. void onProgress(
    1. TransferProgress
    )?,
  7. Future<bool> confirm(
    1. TransferPreflight
    )?,
})

Uploads the local localPath to remoteDir on nodeId, resuming any partial files; the node verifies each file's SHA-256 and reports failure via the session exit code.

Implementation

Future<TransferResult> uploadPath({
  required ClientRuntime client,
  required String nodeId,
  required String localPath,
  required String remoteDir,
  int gzipLevel = kDefaultGzipLevel,
  void Function(TransferProgress)? onProgress,
  Future<bool> Function(TransferPreflight)? confirm,
}) async {
  final manifest = buildManifest(localPath);
  final session = await _openTransfer(
    client,
    nodeId: nodeId,
    direction: 'upload',
    remotePath: remoteDir,
    gzipLevel: gzipLevel,
  );
  try {
    final engine = FileTransferEngine(ClientTransferLink(session));
    await engine.runSender(
      baseDir: manifest.baseDir,
      entries: manifest.entries,
      single: manifest.single,
      gzipLevel: gzipLevel,
      onProgress: onProgress,
      confirm: confirm,
    );
    final code = await session.exitCode;
    if (code == 0) {
      return TransferResult(
        verified: [for (final e in manifest.entries) e.path],
        failures: const {},
      );
    }
    return TransferResult(
      verified: const [],
      failures: {
        for (final e in manifest.entries) e.path: 'node reported a failure',
      },
    );
  } finally {
    await session.close();
  }
}