This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
consume bring your own shim(byos) (#9018)
If there are shims packaged by convention in nupkg. Shim Repository will simply copy it to the right location. The query interface ToolPackageInstance will be in charge of finding the shim folder and filter the right RID. Shim Repository will pick the right file after the folder is located since Shim Repository knows the shim name and it also book keep the files at uninstallation. During development, due to the wrong adapter level. The mock duplicated too much logic. So, I corrected the abstraction level to lower (only create shim). And replaced the existing mock with a much smaller one without any atomic control and file move, copy logic. At the same time. The chmod, which is a IO action, causes problem during tests. So I added adapter layer to it and put it in Util.
- Loading branch information
William Li
authored
Apr 10, 2018
1 parent
98a1ee6
commit b0ee5db
Showing
47 changed files
with
898 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.DotNet.Cli.Utils | ||
{ | ||
internal class FilePermissionSetter : IFilePermissionSetter | ||
{ | ||
public void SetUserExecutionPermission(string path) | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
return; | ||
} | ||
|
||
CommandResult result = new CommandFactory() | ||
.Create("chmod", new[] { "u+x", path }) | ||
.CaptureStdOut() | ||
.CaptureStdErr() | ||
.Execute(); | ||
|
||
if (result.ExitCode != 0) | ||
{ | ||
throw new FilePermissionSettingException(result.StdErr); | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Microsoft.DotNet.Cli.Utils/FilePermissionSettingException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Microsoft.DotNet.Cli.Utils | ||
{ | ||
[Serializable] | ||
internal class FilePermissionSettingException : Exception | ||
{ | ||
public FilePermissionSettingException() | ||
{ | ||
} | ||
|
||
public FilePermissionSettingException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public FilePermissionSettingException(string message, Exception innerException) : base(message, innerException) | ||
{ | ||
} | ||
|
||
protected FilePermissionSettingException(SerializationInfo info, StreamingContext context) : base(info, context) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Microsoft.DotNet.Cli.Utils | ||
{ | ||
internal interface IFilePermissionSetter | ||
{ | ||
void SetUserExecutionPermission(string path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using Microsoft.DotNet.Cli.Utils; | ||
using Microsoft.DotNet.PlatformAbstractions; | ||
using Microsoft.DotNet.Tools.Common; | ||
using Microsoft.Extensions.EnvironmentAbstractions; | ||
|
||
namespace Microsoft.DotNet.ShellShim | ||
{ | ||
internal class AppHostShellShimMaker : IAppHostShellShimMaker | ||
{ | ||
private const string ApphostNameWithoutExtension = "apphost"; | ||
private readonly string _appHostSourceDirectory; | ||
private readonly IFilePermissionSetter _filePermissionSetter; | ||
|
||
public AppHostShellShimMaker(string appHostSourceDirectory = null, IFilePermissionSetter filePermissionSetter = null) | ||
{ | ||
_appHostSourceDirectory = | ||
appHostSourceDirectory | ||
?? Path.Combine(ApplicationEnvironment.ApplicationBasePath, "AppHostTemplate"); | ||
|
||
_filePermissionSetter = | ||
filePermissionSetter | ||
?? new FilePermissionSetter(); | ||
} | ||
|
||
public void CreateApphostShellShim(FilePath entryPoint, FilePath shimPath) | ||
{ | ||
string appHostSourcePath; | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
appHostSourcePath = Path.Combine(_appHostSourceDirectory, ApphostNameWithoutExtension + ".exe"); | ||
} | ||
else | ||
{ | ||
appHostSourcePath = Path.Combine(_appHostSourceDirectory, ApphostNameWithoutExtension); | ||
} | ||
|
||
var appHostDestinationFilePath = shimPath.Value; | ||
var appBinaryFilePath = PathUtility.GetRelativePath(appHostDestinationFilePath, entryPoint.Value); | ||
|
||
EmbedAppNameInHost.EmbedAndReturnModifiedAppHostPath( | ||
appHostSourceFilePath: appHostSourcePath, | ||
appHostDestinationFilePath: appHostDestinationFilePath, | ||
appBinaryFilePath: appBinaryFilePath); | ||
|
||
_filePermissionSetter.SetUserExecutionPermission(appHostDestinationFilePath); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Microsoft.Extensions.EnvironmentAbstractions; | ||
|
||
namespace Microsoft.DotNet.ShellShim | ||
{ | ||
internal interface IAppHostShellShimMaker | ||
{ | ||
void CreateApphostShellShim(FilePath entryPoint, FilePath shimPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.