Revert "Stop converting relative symlinks to absolute."

This reverts commit 9ae3638429.

This change is ok, but cannot be used right now because all existing
binpkgs were created with an old xbps-create(8).
This commit is contained in:
Juan RP
2015-02-19 11:11:58 +01:00
parent 9ae3638429
commit a05e039cce
7 changed files with 105 additions and 20 deletions

View File

@ -454,10 +454,10 @@ xbps_sanitize_path(const char *src)
}
char *
xbps_symlink_target(const char *path)
xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt)
{
struct stat sb;
char *lnk = NULL;
char *p, *p1, *dname, *res = NULL, *lnk = NULL;
ssize_t r;
if (lstat(path, &sb) == -1)
@ -472,5 +472,47 @@ xbps_symlink_target(const char *path)
return NULL;
}
lnk[sb.st_size] = '\0';
return lnk;
if (tgt[0] != '/') {
/*
* target file is relative and wasn't converted to absolute by
* xbps-create(8), just compare it as is.
*/
return lnk;
}
if (strstr(lnk, "./") || lnk[0] != '/') {
/* relative */
p = strdup(path);
assert(p);
dname = dirname(p);
assert(dname);
p = xbps_xasprintf("%s/%s", dname, lnk);
assert(p);
p1 = xbps_sanitize_path(p);
assert(p1);
free(p);
if ((strstr(p1, "./")) && (p = realpath(p1, NULL))) {
if (strcmp(xhp->rootdir, "/") == 0)
res = strdup(p);
else
res = strdup(p + strlen(xhp->rootdir));
free(p);
}
if (res == NULL) {
if (strcmp(xhp->rootdir, "/") == 0)
res = strdup(p1);
else
res = strdup(p1 + strlen(xhp->rootdir));
}
assert(res);
free(lnk);
free(p1);
} else {
/* absolute */
res = lnk;
}
return res;
}