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

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2012-2015 Juan Romero Pardines.
* Copyright (c) 2012-2014 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -234,6 +234,8 @@ ftw_cb(const char *fpath, const struct stat *sb, int type, struct FTW *ftwbuf _u
{
struct xentry *xe = NULL;
const char *filep = NULL;
char *buf, *p, *p2, *dname;
ssize_t r;
/* Ignore metadata files generated by xbps-src and destdir */
if ((strcmp(fpath, ".") == 0) ||
@ -270,10 +272,50 @@ ftw_cb(const char *fpath, const struct stat *sb, int type, struct FTW *ftwbuf _u
*/
xe->type = strdup("links");
assert(xe->type);
xe->target = xbps_symlink_target(fpath);
if (xe->target == NULL)
buf = malloc(sb->st_size+1);
assert(buf);
r = readlink(fpath, buf, sb->st_size+1);
if (r < 0 || r > sb->st_size)
die("failed to process symlink %s:", fpath);
buf[sb->st_size] = '\0';
/*
* Check if symlink is absolute or relative; on the former
* make it absolute for the target object.
*/
if (strstr(buf, "./")) {
p = realpath(fpath, NULL);
if (p == NULL) {
/*
* This symlink points to an unexistent file,
* which might be provided in another package.
* So let's use the same target.
*/
xe->target = strdup(buf);
} else {
/*
* Sanitize destdir just in case.
*/
if ((p2 = realpath(destdir, NULL)) == NULL)
die("failed to sanitize destdir %s: %s", destdir, strerror(errno));
xe->target = strdup(p+strlen(p2));
free(p2);
free(p);
}
} else if (buf[0] != '/') {
/* relative path */
p = strdup(filep);
assert(p);
dname = dirname(p);
assert(dname);
xe->target = xbps_xasprintf("%s/%s", dname, buf);
free(p);
} else {
xe->target = strdup(buf);
}
assert(xe->target);
free(buf);
} else if (type == FTW_F) {
struct xentry *xep;
bool hlink = false;