Skip to content

Commit

Permalink
More CodeQL fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RikuVirtanen committed Jan 18, 2024
1 parent 5e7e8d2 commit b01de07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,11 @@ private Tuple<List<FileItem>, bool> GetSourceFiles()
return new Tuple<List<FileItem>, bool>(fileItems, true);

// create List of FileItems from found files.
foreach (var file in files)
foreach (var file in files.Where(e => Util.FileMatchesMask(Path.GetFileName(e), _batchContext.Source.FileName)))
{
if (Util.FileMatchesMask(Path.GetFileName(file), _batchContext.Source.FileName))
{
var item = new FileItem(Path.GetFullPath(file));
_logger.NotifyInformation(_batchContext, $"FILE LIST {item.FullPath}");
fileItems.Add(item);
}
var item = new FileItem(Path.GetFullPath(file));
_logger.NotifyInformation(_batchContext, $"FILE LIST {item.FullPath}");
fileItems.Add(item);
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Select Note

This foreach loop immediately
maps its iteration variable to another variable
- consider mapping the sequence explicitly using '.Select(...)'.

return new Tuple<List<FileItem>, bool>(fileItems, true);
Expand All @@ -274,17 +271,15 @@ private static void CreateAllDirectories(FtpClient client, string path)
{
// Consistent forward slashes
path = path.Replace(@"\", "/");
foreach (string dir in path.Split('/'))
// Ignoring leading/ending/multiple slashes
foreach (string dir in path.Split('/').Where(e => !string.IsNullOrWhiteSpace(e)))
{
// Ignoring leading/ending/multiple slashes
if (!string.IsNullOrWhiteSpace(dir))
{
if (!client.DirectoryExists(dir))
client.CreateDirectory(dir);
if (!client.DirectoryExists(dir))
client.CreateDirectory(dir);

client.SetWorkingDirectory(dir);
}
client.SetWorkingDirectory(dir);
}

// Going back to default directory
client.SetWorkingDirectory("/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void LogTransferSuccess(SingleFileTransfer transfer, BatchContext context
{
var fileTransferInfoForSuccess = CreateFileTransferInfo(TransferResult.Success, transfer, context);
_fileTransfers.Add(fileTransferInfoForSuccess);
_log.Information("File transfer succeeded: " + transfer.SourceFile);
_log.Information("File transfer succeeded: " + transfer.SourceFile.Name);
}
catch (Exception ex)
{
Expand Down

0 comments on commit b01de07

Please sign in to comment.