public async Task <bool> CopyAsync(string source, string destination, CancellationToken cancellationToken, bool overwrite) { cancellationToken.ThrowIfCancellationRequested(); if (CheckIfExists(destination) && !overwrite) { return(false); } cancellationToken.ThrowIfCancellationRequested(); try { await using var readStream = _environmentFileService.OpenRead(source); await using var writeStream = _environmentFileService.OpenWrite(destination); await readStream.CopyToAsync(writeStream, cancellationToken); } catch (TaskCanceledException) { _logger.LogInformation( $"Cancelled file copy {source} to {destination} (overwrite: {overwrite})"); throw; } catch (Exception ex) { _logger.LogError( $"Failed to copy file {source} to {destination} (overwrite: {overwrite}) with error {ex}"); return(false); } return(true); }
public async Task <bool> CopyAsync(string source, string destination, bool overwrite) { if (CheckIfExists(destination) && !overwrite) { return(false); } try { await using var readStream = _environmentFileService.OpenRead(source); await using var writeStream = _environmentFileService.OpenWrite(destination); await readStream.CopyToAsync(writeStream); } catch (Exception ex) { _logger.LogError( $"Failed to copy file {source} to {destination} (overwrite: {overwrite}) with error {ex}"); return(false); } return(true); }
public Stream OpenRead(string filePath) => _environmentFileService.OpenRead(filePath);