Skip to content

Commit

Permalink
Address code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Nov 19, 2021
1 parent 0183954 commit ef47025
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ internal static partial class Sys

internal static int MkDir(ReadOnlySpan<char> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,26 +300,19 @@ 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<int> stackDir = new(stackalloc int[32]); // 32 arbitrarily chosen
try
{
CreateParentsAndDirectory(fullPath, ref stackDir);
}
finally
{
stackDir.Dispose();
}
CreateParentsAndDirectory(fullPath);
}
else
{
throw Interop.GetExceptionForIoErrno(errorInfo, fullPath, isDirectory: true);
}
}

private static void CreateParentsAndDirectory(string fullPath, ref ValueListBuilder<int> 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<int> stackDir = new(stackalloc int[32]); // 32 arbitrarily chosen
stackDir.Append(fullPath.Length);

int i = fullPath.Length - 1;
Expand Down

0 comments on commit ef47025

Please sign in to comment.