Skip to content
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
6 changes: 3 additions & 3 deletions programs/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,11 +1148,11 @@ static void convertPathnameToDirName(char *pathname)
/* remove trailing '/' chars */
Copy link
Contributor

@Cyan4973 Cyan4973 Aug 13, 2025

Choose a reason for hiding this comment

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

To be fair, I'm not sure if this part of the code makes sense.

The goal of the method convertPathnameToDirName() is to convert a full path of a filename into a just its directory part.

But if pathname ends with a / character, then it already represents a directory name.
In which case, there should be no need to change anything.

In contrast, if we remove the last /, the next stage would strip the last part of the path, and we would end up with the upper directory. And I suspect that's not the wanted behavior.

At this point, my suspicion is that this paragraph is useless, and should just be removed. "Fixing" it could actually introduce problems.

Note: a good follow up could be to improve the tests, by finding scenarios that introduce problems if this function is badly defined. Since our CI signal is all-greens, that means it does not capture the issue.

len = strlen(pathname);
assert(len > 0);
while (pathname[len] == PATH_SEP) {
pathname[len] = '\0';
while (pathname[len-1] == PATH_SEP) {
pathname[len-1] = '\0';
len--;
if (len == 0) return;
}
if (len == 0) return;

/* if input is a single file, return '.' instead. i.e.
* "xyz/abc/file.txt" => "xyz/abc"
Expand Down
Loading