diff --git a/src/Cli/Microsoft.DotNet.InternalAbstractions/DirectoryPath.cs b/src/Cli/Microsoft.DotNet.InternalAbstractions/DirectoryPath.cs index ad2e1c2b4c32..9ffbe1e177e6 100644 --- a/src/Cli/Microsoft.DotNet.InternalAbstractions/DirectoryPath.cs +++ b/src/Cli/Microsoft.DotNet.InternalAbstractions/DirectoryPath.cs @@ -35,19 +35,9 @@ public FilePath WithFile(string fileName) return new FilePath(Path.Combine(Value, fileName)); } - public string ToQuotedString() - { - return $"\"{Value}\""; - } - - public string ToXmlEncodeString() - { - return System.Net.WebUtility.HtmlEncode(Value); - } - public override string ToString() { - return ToQuotedString(); + return $"\"{Value}\""; } public DirectoryPath GetParentPath() @@ -56,8 +46,8 @@ public DirectoryPath GetParentPath() var directoryInfo = new DirectoryInfo(Value); - DirectoryInfo parentDirectory = directoryInfo.Parent; - if (directoryInfo.Parent is null) + DirectoryInfo? parentDirectory = directoryInfo.Parent; + if (parentDirectory is null) { throw new InvalidOperationException(Value + " does not have parent directory."); } @@ -69,8 +59,8 @@ public DirectoryPath GetParentPath() { var directoryInfo = new DirectoryInfo(Value); - DirectoryInfo parentDirectory = directoryInfo.Parent; - if (directoryInfo.Parent is null) + DirectoryInfo? parentDirectory = directoryInfo.Parent; + if (parentDirectory is null) { return null; } diff --git a/src/Cli/Microsoft.DotNet.InternalAbstractions/EnvironmentWrapper.cs b/src/Cli/Microsoft.DotNet.InternalAbstractions/EnvironmentWrapper.cs deleted file mode 100644 index 4691ebe20d2b..000000000000 --- a/src/Cli/Microsoft.DotNet.InternalAbstractions/EnvironmentWrapper.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.Extensions.EnvironmentAbstractions -{ - internal class EnvironmentWrapper : IEnvironment - { - public static IEnvironment Default = new EnvironmentWrapper(); - - public string GetEnvironmentVariable(string name) - { - return Environment.GetEnvironmentVariable(name); - } - } -} diff --git a/src/Cli/Microsoft.DotNet.InternalAbstractions/FilePath.cs b/src/Cli/Microsoft.DotNet.InternalAbstractions/FilePath.cs index 7aaa20cf3a2a..d9ad822f9517 100644 --- a/src/Cli/Microsoft.DotNet.InternalAbstractions/FilePath.cs +++ b/src/Cli/Microsoft.DotNet.InternalAbstractions/FilePath.cs @@ -21,11 +21,6 @@ public FilePath(string value) Value = value; } - public string ToQuotedString() - { - return $"\"{Value}\""; - } - public override string ToString() { return Value; @@ -33,7 +28,7 @@ public override string ToString() public DirectoryPath GetDirectoryPath() { - return new DirectoryPath(Path.GetDirectoryName(Value)); + return new DirectoryPath(Path.GetDirectoryName(Value)!); } } } diff --git a/src/Cli/Microsoft.DotNet.InternalAbstractions/Microsoft.DotNet.InternalAbstractions.csproj b/src/Cli/Microsoft.DotNet.InternalAbstractions/Microsoft.DotNet.InternalAbstractions.csproj index 6260c984866d..57a1d10f3c31 100644 --- a/src/Cli/Microsoft.DotNet.InternalAbstractions/Microsoft.DotNet.InternalAbstractions.csproj +++ b/src/Cli/Microsoft.DotNet.InternalAbstractions/Microsoft.DotNet.InternalAbstractions.csproj @@ -2,7 +2,7 @@ Abstractions for making code that uses file system and environment testable. - netstandard2.0 + $(SdkTargetFramework);net472 true true MicrosoftAspNetCore diff --git a/src/Common/PathUtilities.cs b/src/Common/PathUtilities.cs index 04e6a6cf78fa..387622320628 100644 --- a/src/Common/PathUtilities.cs +++ b/src/Common/PathUtilities.cs @@ -5,41 +5,17 @@ namespace Microsoft.DotNet; static class PathUtilities { - const int S_IRUSR = 256; - const int S_IWUSR = 128; - const int S_IXUSR = 64; - const int S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR; // 700 (octal) Permissions - - const int MAX_NUM_DIRECTORY_CREATE_RETRIES = 2; - public static string CreateTempSubdirectory() - { - return CreateTempSubdirectoryRetry(0); - } - - [DllImport("libc", SetLastError = true)] - private static extern int mkdir(string pathname, int mode); - private static string CreateTempSubdirectoryRetry(int attemptNo) { string path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - int mkdirStatusCode = mkdir(path, S_IRWXU); - if (mkdirStatusCode != 0) - { - int errno = Marshal.GetLastWin32Error(); - if (Directory.Exists(path) && attemptNo < MAX_NUM_DIRECTORY_CREATE_RETRIES) - { - return CreateTempSubdirectoryRetry(attemptNo + 1); - } - else - throw new IOException($"Failed to create a temporary subdirectory {path} with mkdir, error code: {errno}"); - } - } - else - { - Directory.CreateDirectory(path); - } + Directory.CreateDirectory(path); + +#if NET + if (!OperatingSystem.IsWindows()) + File.SetUnixFileMode(path, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); +// #else is only used by Microsoft.NET.TestFramework.csproj for netframework support. nothing to do on unix. +#endif + return path; } } diff --git a/test/dotnet.Tests/CommandTests/ToolRunCommandTests.cs b/test/dotnet.Tests/CommandTests/ToolRunCommandTests.cs index 61c3491ef035..49126e015ed5 100644 --- a/test/dotnet.Tests/CommandTests/ToolRunCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/ToolRunCommandTests.cs @@ -4,7 +4,6 @@ using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.CommandFactory; -using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ToolManifest; using Microsoft.DotNet.ToolPackage; using Microsoft.DotNet.Tools.Tool.Run; @@ -39,7 +38,7 @@ public void WhenRunWithRollForwardOptionItShouldIncludeRollForwardInNativeHost() { CommandName = "dotnet-a", CommandArguments = testForwardArgument - }, toolRunCommand._allowRollForward); + }, toolRunCommand._allowRollForward); result.Should().NotBeNull(); result.Args.Should().Contain("--roll-forward", "Major", fakeExecutable.Value); diff --git a/test/dotnet.Tests/CommandTests/ToolUpdateGlobalOrToolPathCommandTests.cs b/test/dotnet.Tests/CommandTests/ToolUpdateGlobalOrToolPathCommandTests.cs index eff841438773..2f5e7266243b 100644 --- a/test/dotnet.Tests/CommandTests/ToolUpdateGlobalOrToolPathCommandTests.cs +++ b/test/dotnet.Tests/CommandTests/ToolUpdateGlobalOrToolPathCommandTests.cs @@ -14,7 +14,6 @@ using Microsoft.Extensions.EnvironmentAbstractions; using LocalizableStrings = Microsoft.DotNet.Tools.Tool.Update.LocalizableStrings; using Parser = Microsoft.DotNet.Cli.Parser; -using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.Tools.Tool.Uninstall; namespace Microsoft.DotNet.Tests.Commands.Tool @@ -383,7 +382,7 @@ public void GivenAnExistedLowerversionWhenReinstallThrowsItRollsBack() _reporter.Lines.Clear(); ParseResult result = Parser.Instance.Parse("dotnet tool update " + $"-g {_packageId}"); - + var command = new ToolUpdateGlobalOrToolPathCommand( result, (location, forwardArguments, currentWorkingDirectory) => (_store, _store, @@ -421,7 +420,7 @@ public void GivenPackagedShimIsProvidedWhenRunWithPackageIdItCreatesShimUsingPac string options = $"-g {_packageId}"; ParseResult result = Parser.Instance.Parse("dotnet tool update " + options); - + var command = new ToolUpdateGlobalOrToolPathCommand( result, (_, _, _) => (_store, _store, new ToolPackageDownloaderMock(