Skip to content

posixfile.cpp: remove redundant realpath() call #13845

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
8 changes: 1 addition & 7 deletions src/osd/modules/file/posixfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,20 +425,14 @@ std::error_condition osd_get_full_path(std::string &dst, std::string const &path
dst = canonical.get();
return std::error_condition();
}

std::vector<char> path_buffer(PATH_MAX);
if (::realpath(path.c_str(), &path_buffer[0]))
{
dst = &path_buffer[0];
return std::error_condition();
}
else if (path[0] == PATHSEPCH)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this still have the else, which belongs to a now-removed if ()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a chain like

if (cond1) {
   // code for cond1
   return ...
} else if (cond2) {
   // code for cond2
   return ...
} else {
   // code for else
   return ...
}

which is equivalent to

if (cond1) {
   // code for cond1
   return ...
}
if (cond2) {
   // code for cond2
   return ...
}
// code for else
return ...

I replaced the now-removed if called realpath() with a buffer with the if that calls realpath(..., nullptr), as it does the same thing, keeping the if chain as it was for consistency.

{
dst = path;
return std::error_condition();
}
else
{
std::vector<char> path_buffer(128);
while (!::getcwd(&path_buffer[0], path_buffer.size()))
{
if (errno != ERANGE)
Expand Down
Loading