File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -43,22 +43,25 @@ namespace TestHelpers
4343// Recursive helper function to create a directory tree.
4444void createDirectoryTree (const std::filesystem::path& directoryTree)
4545{
46+ // Normalize the path to resolve any ".." components
47+ std::filesystem::path normalizedPath = directoryTree.lexically_normal ();
48+
4649 // Nothing to do, end recursion.
47- if (std::filesystem::exists (directoryTree ))
50+ if (std::filesystem::exists (normalizedPath ))
4851 {
4952 return ;
5053 }
5154
5255 // Make sure the parent directory exists.
5356 // Note: std::filesystem::create_directory can only create the leaf of the directory tree,
5457 // hence the recursion.
55- createDirectoryTree (directoryTree .parent_path ());
58+ createDirectoryTree (normalizedPath .parent_path ());
5659
5760 // Create the final directory.
58- if (!std::filesystem::create_directory (directoryTree ))
61+ if (!std::filesystem::create_directory (normalizedPath ))
5962 {
6063 throw std::runtime_error (
61- std::string (" Failed to create the directory: " ) + directoryTree .string ());
64+ std::string (" Failed to create the directory: " ) + normalizedPath .string ());
6265 }
6366}
6467
You can’t perform that action at this time.
0 commit comments