From 46ae778cb358a59e9612d0b8aa0407ddcb65b5ad Mon Sep 17 00:00:00 2001 From: Jan Paolo Go Date: Wed, 15 May 2019 19:10:42 -0500 Subject: [PATCH 1/2] initial commit fix issue in simplest manner --- src/Squirrel/UpdateManager.ApplyReleases.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Squirrel/UpdateManager.ApplyReleases.cs b/src/Squirrel/UpdateManager.ApplyReleases.cs index 09af8c54b..991ab5c61 100644 --- a/src/Squirrel/UpdateManager.ApplyReleases.cs +++ b/src/Squirrel/UpdateManager.ApplyReleases.cs @@ -451,7 +451,7 @@ void fixPinnedExecutables(SemanticVersion newCurrentVersion, bool removeAll = fa try { if (shortcut == null) continue; if (String.IsNullOrWhiteSpace(shortcut.Target)) continue; - if (!shortcut.Target.StartsWith(rootAppDirectory, StringComparison.OrdinalIgnoreCase)) continue; + if (!Path.GetDirectoryName(shortcut.Target).Equals(rootAppDirectory, StringComparison.OrdinalIgnoreCase)) continue; if (removeAll) { Utility.DeleteFileHarder(shortcut.ShortCutFile); From 1830f41ef5e7b35f88022c2a54751a5701d4dc7c Mon Sep 17 00:00:00 2001 From: Jan Paolo Go Date: Wed, 15 May 2019 19:21:24 -0500 Subject: [PATCH 2/2] extract to method so it's unit-testable --- src/Squirrel/ShellFile.cs | 12 +++++++++++ src/Squirrel/UpdateManager.ApplyReleases.cs | 2 +- test/ShellLinkTests.cs | 23 +++++++++++++++++++++ test/Squirrel.Tests.csproj | 1 + 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/ShellLinkTests.cs diff --git a/src/Squirrel/ShellFile.cs b/src/Squirrel/ShellFile.cs index c69214245..1564fb334 100644 --- a/src/Squirrel/ShellFile.cs +++ b/src/Squirrel/ShellFile.cs @@ -1053,6 +1053,18 @@ ushort timeOut this.shortcutFile = linkFile; } } + + /// + /// Indicates whether the target is in the given directory. + /// + /// The directory. + /// true if the target is in the given directory; otherwise, false. + internal bool IsTargetInDirectory( + string directory) + { + return System.IO.Path.GetDirectoryName(Target) + .Equals(directory, StringComparison.OrdinalIgnoreCase); + } } /// diff --git a/src/Squirrel/UpdateManager.ApplyReleases.cs b/src/Squirrel/UpdateManager.ApplyReleases.cs index 991ab5c61..ff6e6b18b 100644 --- a/src/Squirrel/UpdateManager.ApplyReleases.cs +++ b/src/Squirrel/UpdateManager.ApplyReleases.cs @@ -451,7 +451,7 @@ void fixPinnedExecutables(SemanticVersion newCurrentVersion, bool removeAll = fa try { if (shortcut == null) continue; if (String.IsNullOrWhiteSpace(shortcut.Target)) continue; - if (!Path.GetDirectoryName(shortcut.Target).Equals(rootAppDirectory, StringComparison.OrdinalIgnoreCase)) continue; + if (!shortcut.IsTargetInDirectory(rootAppDirectory)) continue; if (removeAll) { Utility.DeleteFileHarder(shortcut.ShortCutFile); diff --git a/test/ShellLinkTests.cs b/test/ShellLinkTests.cs new file mode 100644 index 000000000..74af97fb7 --- /dev/null +++ b/test/ShellLinkTests.cs @@ -0,0 +1,23 @@ +using Squirrel.Shell; +using Xunit; + +namespace Squirrel.Tests +{ + public class ShellLinkTests + { + [Theory] + [InlineData(@"C:\MyApp\MyApp.exe", @"C:\MyApp", true)] + [InlineData(@"C:\MyApp\MyApp.exe", @"C:\MyAppTwo", false)] + public void IsTargetInDirectoryTest( + string target, + string directory, + bool isTargetInDirectory) + { + var shellLink = new ShellLink + { + Target = target + }; + Assert.Equal(isTargetInDirectory, shellLink.IsTargetInDirectory(directory)); + } + } +} diff --git a/test/Squirrel.Tests.csproj b/test/Squirrel.Tests.csproj index 6c89f4fb3..8be9bfb40 100644 --- a/test/Squirrel.Tests.csproj +++ b/test/Squirrel.Tests.csproj @@ -96,6 +96,7 @@ +