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

[C] add and use aeron_mkdir_recursive #1602

Merged
merged 4 commits into from
May 26, 2024
Merged
Changes from 1 commit
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
35 changes: 19 additions & 16 deletions aeron-client/src/main/c/util/aeron_fileutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,40 +462,43 @@ int aeron_mkdir_recursive(const char *pathname, int permission)

if (errno != ENOENT)
{
AERON_SET_ERR(errno, "aeron_mkdir failed for %s", pathname);
return -1;
nbradac marked this conversation as resolved.
Show resolved Hide resolved
}

char *_pathname = strdup(pathname);
char *p;
int rc = -1;

for (p = _pathname + strlen(_pathname) - 1; p != _pathname; p--)
{
if (*p == AERON_FILE_SEP)
{
*p = '\0';

// _pathname is now the parent directory of the original pathname
rc = aeron_mkdir_recursive(_pathname, permission);
break;
}
}
int rc = aeron_mkdir_recursive(_pathname, permission);

if (p == _pathname)
{
// after iterating through _pathname, we didn't find a separator
rc = -1;
free(_pathname);

if (0 == rc)
{
// if rc is 0, then we were able to create the parent directory
// so retry the original pathname
return aeron_mkdir(pathname, permission);
}
else
{
AERON_APPEND_ERR("%s", "");
nbradac marked this conversation as resolved.
Show resolved Hide resolved
return rc;
}
}
}

free(_pathname);

if (rc == 0)
{
// if rc is 0, then we were able to create the parent directory
// so retry the original pathname
return aeron_mkdir(pathname, permission);
}
AERON_SET_ERR(EINVAL, "aeron_mkdir_recursive failed to find parent directory in %s", pathname);

return rc;
return -1;
}

#include <inttypes.h>
Expand Down
Loading