Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix paths resolving without a leading '/' #31

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
18 changes: 12 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,14 +884,20 @@ read_one_repos_conf(const char *repos_conf, char **primary)
void *ele;
size_t n;
char *overlay;
char rootovrl[_Q_PATH_MAX];
char rootovrl[_Q_PATH_MAX], portroot_real[_Q_PATH_MAX];
bool use_portroot_real, portroot_empty_or_root;

/* try not to get confused by symlinks etc. */
snprintf(rootovrl, sizeof(rootovrl), "%s%s", portroot, e);
n = strlen(portroot);
if (realpath(rootovrl, rrepo) != NULL &&
strncmp(rrepo, portroot, n) == 0)
e = rrepo + n;
use_portroot_real = realpath(portroot, portroot_real) != NULL;
n = use_portroot_real ? strlen(portroot_real) : strlen(portroot);
portroot_empty_or_root = n == 0 || strncmp(use_portroot_real ? portroot_real : portroot,
"/", 2) == 0;
snprintf(rootovrl, sizeof(rootovrl), "%s/%s", use_portroot_real ? portroot_real :
portroot, e);

if (realpath(rootovrl, rrepo) != NULL && (portroot_empty_or_root ||
(use_portroot_real && strncmp(rrepo, portroot_real, n) == 0)))
e = rrepo + (portroot_empty_or_root ? 0 : n);
else
e = rootovrl + n;

Expand Down