Stop converting relative symlinks to absolute.

There's no reason to make them absolute, simply store in the metadata
the target file as is. This vastly simplifies the code and makes all
test pass correctly.
This commit is contained in:
Juan RP
2015-02-19 11:04:34 +01:00
parent 2f9dd7237b
commit 9ae3638429
7 changed files with 20 additions and 105 deletions

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2012-2014 Juan Romero Pardines.
* Copyright (c) 2012-2015 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -234,8 +234,6 @@ 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) ||
@@ -272,50 +270,10 @@ ftw_cb(const char *fpath, const struct stat *sb, int type, struct FTW *ftwbuf _u
*/
xe->type = strdup("links");
assert(xe->type);
buf = malloc(sb->st_size+1);
assert(buf);
r = readlink(fpath, buf, sb->st_size+1);
if (r < 0 || r > sb->st_size)
xe->target = xbps_symlink_target(fpath);
if (xe->target == NULL)
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;