Skip to content

Commit

Permalink
MergeCommand: when handling --input-file-(nul-)list, avoid adding dup…
Browse files Browse the repository at this point in the history
…licates and empty lines, if any

Signed-off-by: Jim Klimov <jimklimov@gmail.com>
  • Loading branch information
jimklimov committed Jul 19, 2023
1 parent 89499f5 commit 2cd9f5e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/cyclonedx/Commands/MergeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ public static async Task<int> Merge(MergeCommandOptions options)
{
Console.WriteLine($"Adding to input file list from " + OneInputFileList);
string[] lines = File.ReadAllLines(OneInputFileList);
InputFiles.AddRange(lines);
Console.WriteLine($"Got " + lines.Length + " entries from " + OneInputFileList);
int count = 0;
foreach (string line in lines) {
if (string.IsNullOrEmpty(line)) continue;
if (InputFiles.Contains(line)) continue;
InputFiles.Add(line);
count++;
}
Console.WriteLine($"Got " + count + " new entries from " + OneInputFileList);
}
}

Expand All @@ -99,8 +105,14 @@ public static async Task<int> Merge(MergeCommandOptions options)
{
Console.WriteLine($"Adding to input file list from " + OneInputFileList);
string[] lines = File.ReadAllText(OneInputFileList).Split('\0');
InputFiles.AddRange(lines);
Console.WriteLine($"Got " + lines.Length + " entries from " + OneInputFileList);
int count = 0;
foreach (string line in lines) {
if (string.IsNullOrEmpty(line)) continue;
if (InputFiles.Contains(line)) continue;
InputFiles.Add(line);
count++;
}
Console.WriteLine($"Got " + count + " new entries from " + OneInputFileList);
}
}

Expand Down

0 comments on commit 2cd9f5e

Please sign in to comment.