Skip to content

Commit

Permalink
Fix ignored paths used by binary tool (#40777)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellahathaway committed May 10, 2024
1 parent c6efaba commit d5cb00f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 41 deletions.
6 changes: 6 additions & 0 deletions src/SourceBuild/content/eng/allowed-sb-binaries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# This file is used by the Binary Tool to remove binaries from the VMR
# If importing a file, include the relative path to the file

# Well known non-checked in infrastructure
.git/
.dotnet/
.packages/
prereqs/packages/

**/*.bmp
**/*.doc
**/*.docx
Expand Down
41 changes: 0 additions & 41 deletions src/SourceBuild/content/eng/tools/BinaryToolKit/DetectBinaries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static class DetectBinaries

var matcher = new Matcher(StringComparison.Ordinal);
matcher.AddInclude("**/*");
matcher.AddExcludePatterns(await GetIgnoredPatternsAsync(targetDirectory));

IEnumerable<string> matchingFiles = matcher.GetResultsInFullPath(targetDirectory);

Expand All @@ -45,46 +44,6 @@ public static class DetectBinaries
return unmatchedBinaryFiles;
}

private static async Task<List<string>> GetIgnoredPatternsAsync(string targetDirectory)
{
string gitDirectory = Path.Combine(targetDirectory, ".git");
bool isGitRepo = Directory.Exists(gitDirectory);

try
{
if (!isGitRepo)
{
// Configure a fake git repo to use so that we can run git clean -ndx
await ExecuteProcessAsync("git", $"-C {targetDirectory} init -q");
}

await ExecuteProcessAsync("git", $"-C {targetDirectory} config --global safe.directory {targetDirectory}");

string output = await ExecuteProcessAsync("git", $"-C {targetDirectory} clean -ndx");

List<string> ignoredPaths = output.Split(Environment.NewLine)
.Select(line => GitCleanRegex.Match(line))
.Where(match => match.Success)
.Select(match => match.Groups[3].Value)
.ToList();

if (isGitRepo)
{
ignoredPaths.Add(".git");
}

return ignoredPaths;
}
finally
{
// Ensure .git directory is deleted if it wasn't originally a git repo
if (!isGitRepo && Directory.Exists(gitDirectory))
{
Directory.Delete(gitDirectory, true);
}
}
}

private static async Task<bool> IsBinaryAsync(string filePath)
{
// Using the GNU diff heuristic to determine if a file is binary or not.
Expand Down

0 comments on commit d5cb00f

Please sign in to comment.