Skip to content

Commit

Permalink
filesystem: Fix issues related to create_directories
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Jan 5, 2025
1 parent 9d93ad0 commit ccb2e6d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
8 changes: 6 additions & 2 deletions library/src/image.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,12 @@ const image& image::save(const fs::path& filePath, SaveFormat format) const

try
{
// Ensure the directories exists
fs::create_directories(filePath.parent_path());
// Ensure the directories exists if not empty
fs::path parent = filePath.parent_path();
if (!parent.empty())
{
fs::create_directories(parent);
}

writer->SetFileName(filePath.string().c_str());
writer->SetInputData(this->Internals->Image);
Expand Down
8 changes: 6 additions & 2 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,12 @@ bool interactor_impl::recordInteraction(const fs::path& file)

try
{
// Ensure parent directories exists
fs::create_directories(file.parent_path());
// Ensure parent directories exists if not empty
fs::path parent = file.parent_path();
if (!parent.empty())
{
fs::create_directories(parent);
}

// Make sure the recorder is off and streams are cleared
this->Internals->Recorder->Off();
Expand Down
10 changes: 10 additions & 0 deletions library/src/window_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,16 @@ void window_impl::SetCachePath(const fs::path& cachePath)
{
try
{
if (cachePath.empty())
{
throw engine::cache_exception("Provided cache path is empty");
}

if (!fs::is_directory(cachePath))
{
throw engine::cache_exception("Provided cache path is not a directory: " + cachePath.string());
}

// create directories if they do not exist
fs::create_directories(cachePath);
}
Expand Down
4 changes: 4 additions & 0 deletions library/testing/TestSDKEngineExceptions.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ int TestSDKEngineExceptions(int argc, char* argv[])
"get non-existent interactor", [&]() { std::ignore = eng.getInteractor(); });

// Test setCachePath error handling
test.expect<f3d::engine::cache_exception>("set cache path with empty name",
[&]() { eng.setCachePath(""); });
test.expect<f3d::engine::cache_exception>("set cache path with non directory name",
[&]() { eng.setCachePath("/path/to/file.ext"); });
test.expect<f3d::engine::cache_exception>("set cache path with invalid long name",
[&]() { eng.setCachePath("/" + std::string(257, 'x')); });

Expand Down

0 comments on commit ccb2e6d

Please sign in to comment.