aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@FreeBSD.org>2005-09-24 21:19:57 +0000
committerTim Kientzle <kientzle@FreeBSD.org>2005-09-24 21:19:57 +0000
commit512c45ef6c21f05a32737221214a9fbf0823c064 (patch)
tree8dd5343222c5b0661ea0548816d298391e4b38f8 /usr.bin
parent2f3b67647f1d501b17275fbc3cf2d83a28da0881 (diff)
downloadsrc-512c45ef6c21f05a32737221214a9fbf0823c064.tar.gz
src-512c45ef6c21f05a32737221214a9fbf0823c064.zip
Fix -u with absolute paths (e.g., "tar -uf foo.tar /bar") by handling
pathname edits before comparing pathnames on disk to those in the archive. Thanks to: Gareth Bailey, Lowell Gilbert
Notes
Notes: svn path=/head/; revision=150529
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tar/write.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c
index 39743276e9c7..6a78df57a3d6 100644
--- a/usr.bin/tar/write.c
+++ b/usr.bin/tar/write.c
@@ -643,15 +643,12 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
tree_descend(tree);
/*
- * In -u mode, we need to check whether this
- * is newer than what's already in the archive.
- * In all modes, we need to obey --newerXXX flags.
+ * Write the entry. Note that write_entry() handles
+ * pathname editing and newness testing.
*/
- if (new_enough(bsdtar, name, lst)) {
- write_entry(bsdtar, a, lst, name,
- tree_current_pathlen(tree),
- tree_current_access_path(tree));
- }
+ write_entry(bsdtar, a, lst, name,
+ tree_current_pathlen(tree),
+ tree_current_access_path(tree));
}
tree_close(tree);
}
@@ -686,6 +683,13 @@ write_entry(struct bsdtar *bsdtar, struct archive *a, const struct stat *st,
if (edit_pathname(bsdtar, entry))
goto abort;
+ /*
+ * In -u mode, check that the file is newer than what's
+ * already in the archive; in all modes, obey --newerXXX flags.
+ */
+ if (!new_enough(bsdtar, archive_entry_pathname(entry), st))
+ goto abort;
+
if (!S_ISDIR(st->st_mode) && (st->st_nlink > 1))
lookup_hardlink(bsdtar, entry, st);
@@ -1235,10 +1239,6 @@ new_enough(struct bsdtar *bsdtar, const char *path, const struct stat *st)
*/
if (bsdtar->archive_dir != NULL &&
bsdtar->archive_dir->head != NULL) {
- /* Ignore leading './' when comparing names. */
- if (path[0] == '.' && path[1] == '/' && path[2] != '\0')
- path += 2;
-
for (p = bsdtar->archive_dir->head; p != NULL; p = p->next) {
if (strcmp(path, p->name)==0)
return (p->mtime_sec < st->st_mtime ||