From 59945da178b1638fe6fcfb3bdaf4510ecd60ac53 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-lf Date: Tue, 30 Jan 2024 13:37:49 -0800 Subject: [PATCH] Refactor checking directory permissions --- .../UnitTests/Session/EasyLoggingStarterTest.cs | 8 ++++---- Snowflake.Data/Core/Session/EasyLoggingStarter.cs | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Snowflake.Data.Tests/UnitTests/Session/EasyLoggingStarterTest.cs b/Snowflake.Data.Tests/UnitTests/Session/EasyLoggingStarterTest.cs index a0301e835..39796b722 100644 --- a/Snowflake.Data.Tests/UnitTests/Session/EasyLoggingStarterTest.cs +++ b/Snowflake.Data.Tests/UnitTests/Session/EasyLoggingStarterTest.cs @@ -125,7 +125,7 @@ public void TestThatThrowsErrorWhenLogPathIsNotSetAndHomeDirectoryThrowsAnExcept } [Test] - public void TestThatDoesNotFailWhenDirectoryPermissionIsNot600Or700() + public void TestThatDoesNotFailWhenExistingDirectoryContainsUnexpectedPermissions() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -137,8 +137,8 @@ public void TestThatDoesNotFailWhenDirectoryPermissionIsNot600Or700() .Setup(provider => provider.ProvideConfig(ConfigPath)) .Returns(s_configWithInfoLevel); t_directoryOperations - .Setup(dir => dir.Exists(ConfigPath)) - .Returns(false); + .Setup(dir => dir.Exists(s_expectedLogPath)) + .Returns(true); t_unixOperations .Setup(unix => unix.GetDirPermissions(s_expectedLogPath)) .Returns(FileAccessPermissions.AllPermissions); @@ -148,7 +148,7 @@ public void TestThatDoesNotFailWhenDirectoryPermissionIsNot600Or700() // assert t_unixOperations.Verify(u => u.CreateDirectoryWithPermissions(s_expectedLogPath, - FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IXUSR), Times.Once); + FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IXUSR), Times.Never); } [Test] diff --git a/Snowflake.Data/Core/Session/EasyLoggingStarter.cs b/Snowflake.Data/Core/Session/EasyLoggingStarter.cs index 17d6ed26e..ab155b8cd 100644 --- a/Snowflake.Data/Core/Session/EasyLoggingStarter.cs +++ b/Snowflake.Data/Core/Session/EasyLoggingStarter.cs @@ -135,9 +135,12 @@ private string GetLogPath(string logPath) } _unixOperations.CreateDirectoryWithPermissions(pathWithDotnetSubdirectory, FilePermissions.S_IRUSR | FilePermissions.S_IWUSR | FilePermissions.S_IXUSR); - CheckDirPermissionsOnlyAllowUser(pathWithDotnetSubdirectory); } } + else + { + CheckDirPermissionsOnlyAllowUser(pathWithDotnetSubdirectory); + } return pathWithDotnetSubdirectory; }