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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user