Skip to content

Commit

Permalink
Ignore '_._' files (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfederm committed Aug 8, 2024
1 parent cf71e8b commit 7c0f1c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" ExcludeAssets="Runtime, Compile" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" ExcludeAssets="Build" />
</ItemGroup>
Expand Down
29 changes: 25 additions & 4 deletions src/PackagesConfigConverter/PackageReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,31 @@ private IReadOnlyCollection<string> GetPackageFolderNames()
return Array.Empty<string>();
}

return new HashSet<string>(
Directory.EnumerateDirectories(RepositoryInstalledPath)
.Select(i => i.Substring(i.LastIndexOf(Path.DirectorySeparatorChar) + 1)),
StringComparer.OrdinalIgnoreCase);
var folderNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (string dir in Directory.EnumerateDirectories(RepositoryInstalledPath))
{
if (HasAnyRealFiles(dir))
{
string dirName = dir.Substring(dir.LastIndexOf(Path.DirectorySeparatorChar) + 1);
folderNames.Add(dirName);
}
}

return folderNames;

static bool HasAnyRealFiles(string dir)
{
// Ignore the special "_._" file.
foreach (string file in Directory.EnumerateFiles(dir, "*", SearchOption.AllDirectories))
{
if (!Path.GetFileName(file).Equals("_._"))
{
return true;
}
}

return false;
}
}
}
}

0 comments on commit 7c0f1c3

Please sign in to comment.