Skip to content

Commit

Permalink
Removed unecessary cancellationTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
RikuVirtanen committed Jul 25, 2023
1 parent 607ee33 commit ce4fc91
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Frends.SFTP.UploadFiles/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## [2.7.1] - 2023-07-25
### Fixed
### Added
- Added SFTPClient.OperationTimeout which should cause timeout during operations if the Task becomes stuck.

## [2.7.0] - 2023-06-08
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public virtual void OneTimeSetup()
Directory = _workDir,
FileName = "SFTPUploadTestFile1.txt",
Action = SourceAction.Error,
Operation = SourceOperation.Nothing,
Operation = SourceOperation.Nothing
};

_destination = new Destination
Expand All @@ -46,7 +46,7 @@ public virtual void OneTimeSetup()
RenameDestinationFileDuringTransfer = true,
CreateDestinationDirectories = true,
PreserveLastModified = false,
OperationLog = true,
OperationLog = true
};

_info = new Info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public FileTransferResult Run()
client.Connect();

var singleTransfer = new SingleFileTransfer(file, DestinationDirectoryWithMacrosExtended, _batchContext, client, _renamingPolicy, _logger);
var result = singleTransfer.TransferSingleFile(_cancellationToken);
var result = singleTransfer.TransferSingleFile();
_result.Add(result);
}
client.Disconnect();
Expand Down Expand Up @@ -527,7 +527,6 @@ private static FileTransferResult FormFailedFileTransferResult(string userResult

private FileTransferResult FormResultFromSingleTransferResults(List<SingleFileTransferResult> singleResults)
{
_cancellationToken.ThrowIfCancellationRequested();
var success = singleResults.All(x => x.Success);
var actionSkipped = success && singleResults.All(x => x.ActionSkipped);
var userResultMessage = GetUserResultMessage(singleResults.ToList(), _cancellationToken);
Expand Down Expand Up @@ -558,8 +557,6 @@ private static string GetUserResultMessage(IList<SingleFileTransferResult> resul
{
var userResultMessage = string.Empty;

cancellationToken.ThrowIfCancellationRequested();

var errorMessages = results.SelectMany(x => x.ErrorMessages).ToList();
if (errorMessages.Any())
userResultMessage = MessageJoin(userResultMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,16 @@ public SingleFileTransfer(FileItem file, string destinationDirectory, BatchConte
/// </summary>
internal TransferState State { get; set; }

internal SingleFileTransferResult TransferSingleFile(CancellationToken cancellationToken)
internal SingleFileTransferResult TransferSingleFile()
{
try
{
cancellationToken.ThrowIfCancellationRequested();

_result.TransferredFile = SourceFile.Name;
_result.TransferredFilePath = SourceFile.FullPath;

GetSourceFile(cancellationToken);
GetSourceFile();

ExecuteSourceOperationMoveOrRename(cancellationToken);
ExecuteSourceOperationMoveOrRename();

if (DestinationFileExists(DestinationFileWithMacrosExpanded))
{
Expand All @@ -69,13 +67,13 @@ internal SingleFileTransferResult TransferSingleFile(CancellationToken cancellat
AppendDestinationFile();
break;
case DestinationAction.Overwrite:
PutDestinationFile(cancellationToken, removeExisting: true);
PutDestinationFile(removeExisting: true);
break;
case DestinationAction.Error:
throw new DestinationFileExistsException(Path.GetFileName(DestinationFileWithMacrosExpanded));
}
}
else PutDestinationFile(cancellationToken);
else PutDestinationFile();

if (BatchContext.Options.PreserveLastModified) RestoreModified();

Expand All @@ -97,9 +95,8 @@ internal SingleFileTransferResult TransferSingleFile(CancellationToken cancellat
return _result;
}

private void GetSourceFile(CancellationToken cancellationToken)
private void GetSourceFile()
{
cancellationToken.ThrowIfCancellationRequested();
if (BatchContext.Options.RenameSourceFileBeforeTransfer)
RenameSourceFile();
else
Expand Down Expand Up @@ -200,12 +197,10 @@ private static string GetSourceFileContent(string filePath, bool addNewLine, Enc

}

private void PutDestinationFile(CancellationToken cancellationToken, bool removeExisting = false)
private void PutDestinationFile(bool removeExisting = false)
{
var doRename = BatchContext.Options.RenameDestinationFileDuringTransfer;

cancellationToken.ThrowIfCancellationRequested();

DestinationFileDuringTransfer = doRename ? Path.Combine(Path.GetDirectoryName(DestinationFileWithMacrosExpanded), Util.CreateUniqueFileName(BatchContext.Options.DestinationFileExtension)) : DestinationFileWithMacrosExpanded;
if (DestinationFileWithMacrosExpanded.Contains('/')) DestinationFileDuringTransfer = DestinationFileDuringTransfer.Replace("\\", "/");

Expand Down Expand Up @@ -255,9 +250,8 @@ private void RestoreModified()
return;
}

private void ExecuteSourceOperationMoveOrRename(CancellationToken cancellationToken)
private void ExecuteSourceOperationMoveOrRename()
{
cancellationToken.ThrowIfCancellationRequested();
if (BatchContext.Source.Operation == SourceOperation.Move)
{
var moveToPath = _renamingPolicy.ExpandDirectoryForMacros(BatchContext.Source.DirectoryToMoveAfterTransfer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static Result UploadFiles(
BatchTransferStartTime = DateTime.Now,
Source = source,
Destination = destination,
Connection = connection,
Connection = connection
};

var fileTransporter = new FileTransporter(logger, _batchContext, executionId, cancellationToken);
Expand Down

0 comments on commit ce4fc91

Please sign in to comment.