Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS agnostic path separator #3064

Merged
merged 7 commits into from
Feb 17, 2025
Merged

OS agnostic path separator #3064

merged 7 commits into from
Feb 17, 2025

Conversation

rasapala
Copy link
Collaborator

@rasapala rasapala commented Feb 12, 2025

🛠 Summary

JIRA CVS-160424
Switch to os agnostic path separator.

🧪 Checklist

  • Unit tests added.
  • The documentation updated.
  • Change follows security best practices.
    ``

this->setBasePath(this->getGraphName() + "/");
else if (providedBasePath.back() == '/')
this->setBasePath(this->getGraphName() + std::string(1, std::filesystem::path::preferred_separator));
else if (providedBasePath.back() == std::string(1, std::filesystem::path::preferred_separator).back())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this back() needed?

Suggested change
else if (providedBasePath.back() == std::string(1, std::filesystem::path::preferred_separator).back())
else if (providedBasePath.back() == std::string(1, std::filesystem::path::preferred_separator))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need char to compare.

@@ -563,7 +563,7 @@ TEST_F(TestLoadModel, CheckSavedModelHandling) {
auto model_files = modelInstance.getModelFiles();
ASSERT_FALSE(model_files.empty());
#ifdef _WIN32
EXPECT_EQ(model_files.front(), directoryPath + "/test_saved_model/1\\");
EXPECT_EQ(model_files.front(), directoryPath + "/test_saved_model\\1\\");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add function so we could use sth like this without macro's?

Suggested change
EXPECT_EQ(model_files.front(), directoryPath + "/test_saved_model\\1\\");
EXPECT_EQ(model_files.front(), os_agnostic_path(directoryPath + "/test_saved_model/1/"));

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those the only places where we encounter with the different separator handling of Win/Lin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a case by case result for different tests. Part of path is from config or hardcoded and the rest is generated by ovms. So the number of ifdef would be the same.

} else {
rootDirectoryPath = currentWorkingDir + "/";
rootDirectoryPath = currentWorkingDir + std::string(1, std::filesystem::path::preferred_separator);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make macro out of std::string(1, std::filesystem::path::preferred_separator)? or even declare it as constexpr so it is created only once

@@ -116,4 +116,9 @@ std::string FileSystem::findFilePathWithExtension(const std::string& path, const
return std::string();
}

std::string& FileSystem::getOsSeparator() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return const reference

@rasapala rasapala merged commit 7f79b93 into main Feb 17, 2025
13 checks passed
@rasapala rasapala deleted the CVS-160424_win_path_fix branch February 17, 2025 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants