libtar - Fix extraction of hardlinks to use the prefix
Change-Id: I116982ceed722364406b99fb08bc6943afa0390a
diff --git a/libtar/extract.c b/libtar/extract.c
index 8860e50..620513c 100644
--- a/libtar/extract.c
+++ b/libtar/extract.c
@@ -89,7 +89,7 @@
/* switchboard */
int
-tar_extract_file(TAR *t, char *realname)
+tar_extract_file(TAR *t, char *realname, char *prefix)
{
int i;
char *lnp;
@@ -115,7 +115,7 @@
}
else if (TH_ISLNK(t)) {
printf("link\n");
- i = tar_extract_hardlink(t, realname);
+ i = tar_extract_hardlink(t, realname, prefix);
}
else if (TH_ISSYM(t)) {
printf("sym\n");
@@ -300,7 +300,7 @@
/* hardlink */
int
-tar_extract_hardlink(TAR * t, char *realname)
+tar_extract_hardlink(TAR * t, char *realname, char *prefix)
{
char *filename;
char *linktgt = NULL;
@@ -325,7 +325,8 @@
}
else
linktgt = th_get_linkname(t);
-
+ char *newtgt = strdup(linktgt);
+ sprintf(linktgt, "%s/%s", prefix, newtgt);
#ifdef DEBUG
printf(" ==> extracting: %s (link to %s)\n", filename, linktgt);
#endif