Skip to content

Commit

Permalink
Merge pull request #1051 from Squirrel/only-generate-root-stubs
Browse files Browse the repository at this point in the history
Only generate execution stubs for the top-level executables
  • Loading branch information
anaisbetts authored Jun 7, 2017
2 parents 4dac714 + bceb89f commit eacae0f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Squirrel/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,16 @@ public static bool FileIsLikelyPEImage(string name)
return peExtensions.Any(x => ext.Equals(x, StringComparison.OrdinalIgnoreCase));
}

public static bool IsFileTopLevelInPackage(string fullName, string pkgPath)
{
var fn = fullName.ToLowerInvariant();
var pkg = pkgPath.ToLowerInvariant();
var relativePath = fn.Replace(pkg, "");

// NB: We want to match things like `/lib/net45/foo.exe` but not `/lib/net45/bar/foo.exe`
return relativePath.Split(Path.DirectorySeparatorChar).Length == 4;
}

public static void LogIfThrows(this IFullLogger This, LogLevel level, string message, Action block)
{
try {
Expand Down
3 changes: 2 additions & 1 deletion src/Update/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public void Releasify(string package, string targetDir = null, string packagesDi
new DirectoryInfo(pkgPath).GetAllFilesRecursively()
.Where(x => x.Name.ToLowerInvariant().EndsWith(".exe"))
.Where(x => !x.Name.ToLowerInvariant().Contains("squirrel.exe"))
.Where(x => Utility.IsFileTopLevelInPackage(x.FullName, pkgPath))
.Where(x => Utility.ExecutableUsesWin32Subsystem(x.FullName))
.ForEachAsync(x => createExecutableStubForExe(x.FullName))
.Wait();
Expand All @@ -405,7 +406,7 @@ public void Releasify(string package, string targetDir = null, string packagesDi
this.Log().Info("About to sign {0}", x.FullName);
await signPEFile(x.FullName, signingOpts);
})
}, 1)
.Wait();
});

Expand Down
12 changes: 12 additions & 0 deletions test/UtilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ public void FileIsLikelyPEImageTest(string input, bool result)
Assert.Equal(result, Utility.FileIsLikelyPEImage(input));
}

[Theory]
[InlineData("C:\\Users\\bob\\temp\\pkgPath\\lib\\net45\\foo.exe", "C:\\Users\\bob\\temp\\pkgPath", true)]
[InlineData("C:\\Users\\bob\\temp\\pkgPath\\lib\\net45\\node_modules\\foo.exe", "C:\\Users\\bob\\temp\\pkgPath", false)]
[InlineData("C:\\Users\\bob\\temp\\pkgPath\\lib\\net45\\node_modules\\foo\\foo.exe", "C:\\Users\\bob\\temp\\pkgPath", false)]
[InlineData("foo.png", "C:\\Users\\bob\\temp\\pkgPath", false)]
public void IsFileTopLevelInPackageTest(string input, string packagePath, bool result)
{
Assert.Equal(result, Utility.IsFileTopLevelInPackage(input, packagePath));
}



[Fact]
public void WeCanFetchAllProcesses()
{
Expand Down

0 comments on commit eacae0f

Please sign in to comment.