From ef470259723892e06eea5f3982e948f9ee3b3e87 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 19 Nov 2021 08:46:52 +0100 Subject: [PATCH] Address code review feedback --- .../Interop/Unix/System.Native/Interop.MkDir.cs | 3 +-- .../src/System/IO/FileSystem.Unix.cs | 17 +++++------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MkDir.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MkDir.cs index 063f57c64185aa..09a4ae1e3e79ae 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MkDir.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MkDir.cs @@ -14,9 +14,8 @@ internal static partial class Sys internal static int MkDir(ReadOnlySpan path, int mode) { - var converter = new ValueUtf8Converter(stackalloc byte[DefaultPathBufferSize]); + using ValueUtf8Converter converter = new(stackalloc byte[DefaultPathBufferSize]); int result = MkDir(ref MemoryMarshal.GetReference(converter.ConvertAndTerminateString(path)), mode); - converter.Dispose(); return result; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs index c1aebca178af88..e5fd8574f9679b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs @@ -300,17 +300,7 @@ public static void CreateDirectory(string fullPath) } else if (errorInfo.Error == Interop.Error.ENOENT) // Some parts of the path don't exist yet. { - // Try create parents bottom to top and track those that could not - // be created due to missing parents. Then create them top to bottom. - ValueListBuilder stackDir = new(stackalloc int[32]); // 32 arbitrarily chosen - try - { - CreateParentsAndDirectory(fullPath, ref stackDir); - } - finally - { - stackDir.Dispose(); - } + CreateParentsAndDirectory(fullPath); } else { @@ -318,8 +308,11 @@ public static void CreateDirectory(string fullPath) } } - private static void CreateParentsAndDirectory(string fullPath, ref ValueListBuilder stackDir) + private static void CreateParentsAndDirectory(string fullPath) { + // Try create parents bottom to top and track those that could not + // be created due to missing parents. Then create them top to bottom. + using ValueListBuilder stackDir = new(stackalloc int[32]); // 32 arbitrarily chosen stackDir.Append(fullPath.Length); int i = fullPath.Length - 1;