summaryrefslogtreecommitdiffstats
path: root/contrib/libarchive
diff options
context:
space:
mode:
authorae <ae@FreeBSD.org>2014-08-26 13:11:38 +0000
committerae <ae@FreeBSD.org>2014-08-26 13:11:38 +0000
commitf2499d908c3a9f081bcc7e1dd9843e34d38b07b8 (patch)
tree01d8bb7e5ab561570a9ec55045dc3ad930737a38 /contrib/libarchive
parent68084eb457882f37e3e14a2c51a190c448ad465d (diff)
downloadFreeBSD-src-f2499d908c3a9f081bcc7e1dd9843e34d38b07b8.zip
FreeBSD-src-f2499d908c3a9f081bcc7e1dd9843e34d38b07b8.tar.gz
Remove leading '/' from hardlink name when removing them from the
regular file name. This fixes the problem, when bsdtar can not create hardlinks to extracted files. Silence from: kientzle@ MFC after: 1 week Sponsored by: Yandex LLC
Diffstat (limited to 'contrib/libarchive')
-rw-r--r--contrib/libarchive/tar/util.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/contrib/libarchive/tar/util.c b/contrib/libarchive/tar/util.c
index a6f3189..688e1f8 100644
--- a/contrib/libarchive/tar/util.c
+++ b/contrib/libarchive/tar/util.c
@@ -372,6 +372,21 @@ strip_components(const char *p, int elements)
}
}
+static const char*
+strip_leading_slashes(const char *p)
+{
+
+ /* Remove leading "/../", "//", etc. */
+ while (p[0] == '/' || p[0] == '\\') {
+ if (p[1] == '.' && p[2] == '.' && (
+ p[3] == '/' || p[3] == '\\')) {
+ p += 3; /* Remove "/..", leave "/" for next pass. */
+ } else
+ p += 1; /* Remove "/". */
+ }
+ return (p);
+}
+
/*
* Handle --strip-components and any future path-rewriting options.
* Returns non-zero if the pathname should not be extracted.
@@ -474,16 +489,7 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
p += 2;
slashonly = 0;
}
- /* Remove leading "/../", "//", etc. */
- while (p[0] == '/' || p[0] == '\\') {
- if (p[1] == '.' && p[2] == '.' &&
- (p[3] == '/' || p[3] == '\\')) {
- p += 3; /* Remove "/..", leave "/"
- * for next pass. */
- slashonly = 0;
- } else
- p += 1; /* Remove "/". */
- }
+ p = strip_leading_slashes(p);
} while (rp != p);
if (p != name && !bsdtar->warned_lead_slash) {
@@ -504,6 +510,19 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
name = ".";
else
name = p;
+
+ p = archive_entry_hardlink(entry);
+ if (p != NULL) {
+ rp = strip_leading_slashes(p);
+ if (rp == '\0')
+ return (1);
+ if (rp != p) {
+ char *linkname = strdup(rp);
+
+ archive_entry_copy_hardlink(entry, linkname);
+ free(linkname);
+ }
+ }
} else {
/* Strip redundant leading '/' characters. */
while (name[0] == '/' && name[1] == '/')
OpenPOWER on IntegriCloud