Skip to content
Merged
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
Next Next commit
remove List<int> allocation
  • Loading branch information
adamsitnik committed Nov 18, 2021
commit 432f276d740b8215a2f8ac62494bcb30cd50921e
Original file line number Diff line number Diff line change
Expand Up @@ -298,24 +298,29 @@ public static void CreateDirectory(string fullPath)
{
return; // Path already exists and it's a directory.
}
else if (errorInfo.Error == Interop.Error.ENOENT)
else if (errorInfo.Error == Interop.Error.ENOENT) // Some parts of the path don't exist yet.
{
// Some parts of the path don't exist yet.
CreateParentsAndDirectory(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.
ValueListBuilder<int> stackDir = new(stackalloc int[32]); // 32 arbitrarily chosen
try
{
CreateParentsAndDirectory(fullPath, stackDir);
}
finally
{
stackDir.Dispose();
}
}
else
{
throw Interop.GetExceptionForIoErrno(errorInfo, fullPath, isDirectory: true);
}
}

public static void CreateParentsAndDirectory(string fullPath)
public static void CreateParentsAndDirectory(string fullPath, ValueListBuilder<int> stackDir)
{
// Try create parents bottom to top and track those that could not
// be created due to missing parents. Then create them top to bottom.
List<int> stackDir = new();

stackDir.Add(fullPath.Length);
stackDir.Append(fullPath.Length);

int i = fullPath.Length - 1;
// Trim trailing separator.
Expand Down Expand Up @@ -348,7 +353,7 @@ public static void CreateParentsAndDirectory(string fullPath)
// We'll try to create its parent on the next iteration.

// Track this path for later creation.
stackDir.Add(mkdirPath.Length);
stackDir.Append(mkdirPath.Length);
}
else if (errorInfo.Error == Interop.Error.EEXIST)
{
Expand All @@ -364,7 +369,7 @@ public static void CreateParentsAndDirectory(string fullPath)
} while (i > 0);

// Create directories that had missing parents.
for (i = stackDir.Count - 1; i >= 0; i--)
for (i = stackDir.Length - 1; i >= 0; i--)
{
ReadOnlySpan<char> mkdirPath = fullPath.AsSpan(0, stackDir[i]);
int result = Interop.Sys.MkDir(mkdirPath, (int)Interop.Sys.Permissions.Mask);
Expand Down