Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address code review feedback
  • Loading branch information
adamsitnik committed Nov 19, 2021
commit ef470259723892e06eea5f3982e948f9ee3b3e87
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