Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
<Project>
<!--
SixLabors.ImageSharp 3.1.12 is the last 3.1.x release and carries these advisories; no 3.1.x
release patches them. The fix is 4.x, which moved to a split licence, so the package is pinned to
3.1.x deliberately and these are accepted until ImageSharp is upgraded or replaced. Each advisory
is named individually so a new one still fails the restore. Revisit this list on every ImageSharp
bump, and keep it the only place these are declared: a second copy fails restore with NU1508.
-->
<ItemGroup>
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-j3p4-wp97-rph4" />
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-j9gm-c75j-xc9q" />
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-jjfr-hcj7-qf5w" />
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-gwg2-r3hj-4w44" />
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-wmxv-xphr-5c9g" />
Comment on lines +10 to +14
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions IconHelper.Test/ProcessDirectoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@
Assert.IsTrue(File.Exists(Path.Combine(output, "good.png")));
}

[TestMethod]
public void SkipsFileManagerMetadataWithoutCountingItAsFailed()
{
using TempDirectory temp = new();
string input = temp.Combine("in");
string output = temp.Combine("out");
Directory.CreateDirectory(input);
File.WriteAllBytes(Path.Join(input, ".DS_Store"), [0, 0, 0, 1, (byte)'B', (byte)'u', (byte)'d', (byte)'1']);
File.WriteAllText(Path.Join(input, "._good.png"), "AppleDouble resource fork");
File.WriteAllText(Path.Join(input, "desktop.ini"), "[.ShellClassInfo]\r\n");
File.WriteAllText(Path.Join(input, "THUMBS.DB"), "not an image");
File.WriteAllText(Path.Join(input, "ehthumbs.db"), "not an image");
WritePng(Path.Join(input, "good.png"), 64);

BatchResult result = IconHelper.ProcessDirectory(ArgumentsFor(input, output), NamedColors.White);

Assert.AreEqual(new BatchResult(1, 0), result, "File-manager metadata should be neither written nor failed.");
Assert.AreEqual(IconHelper.ExitSuccess, IconHelper.ExitCodeFor(result));
Assert.AreEqual(1, Directory.GetFiles(output).Length);

Check warning on line 187 in IconHelper.Test/ProcessDirectoryTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'Assert.HasCount' instead of 'Assert.AreEqual'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_IconHelper&issues=AaEgQOdidH295o1mklhO&open=AaEgQOdidH295o1mklhO&pullRequest=142
}

[TestMethod]
public void ReportsAndSkipsAFileThatCannotBeOpened()
{
Expand Down
15 changes: 14 additions & 1 deletion IconHelper/IconHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ internal static BatchResult ProcessDirectory(Arguments args, Color color)
// whole string let a directory anywhere above the input -- a user name, a date stamp,
// a project folder -- decide that every file below it was already generated. That
// failure is silent and total: nothing is written and the run still exits 0.
if (Path.GetFileName(file).Contains(".new.png", StringComparison.Ordinal))
string fileName = Path.GetFileName(file);
if (fileName.Contains(".new.png", StringComparison.Ordinal) || IsFileManagerMetadata(fileName))
{
continue;
}
Expand Down Expand Up @@ -169,6 +170,18 @@ internal static BatchResult ProcessDirectory(Arguments args, Color color)
return new BatchResult(processed, failed);
}

/// <summary>
/// Names that Finder and Explorer drop into any folder they open: dot-files such as .DS_Store and
/// ._ AppleDouble files, plus Thumbs.db, ehthumbs.db and desktop.ini. They are not icons, so they
/// count as neither written nor failed; counting them as failures made every batch on such a
/// folder exit 2 and taught scripts to ignore the code that reports real decode failures.
/// </summary>
internal static bool IsFileManagerMetadata(string fileName)
=> fileName.StartsWith('.')
|| fileName.Equals("Thumbs.db", StringComparison.OrdinalIgnoreCase)
|| fileName.Equals("ehthumbs.db", StringComparison.OrdinalIgnoreCase)
|| fileName.Equals("desktop.ini", StringComparison.OrdinalIgnoreCase);

/// <summary>
/// Reduces an icon to a coverage mask: every pixel carries the flat target colour and the shape
/// lives entirely in the alpha channel. The result is trimmed of its transparent margins, centred
Expand Down
Loading