diff --git a/usr.bin/tar/tree.c b/usr.bin/tar/tree.c index 4528eea3c15b..944a787bcf47 100644 --- a/usr.bin/tar/tree.c +++ b/usr.bin/tar/tree.c @@ -311,13 +311,14 @@ tree_next(struct tree *t) t->tree_errno = errno; return (t->visit_type = TREE_ERROR_DIR); } + t->depth++; t->d = opendir("."); if (t->d == NULL) { + tree_ascend(t); /* Undo "chdir" */ tree_pop(t); t->tree_errno = errno; return (t->visit_type = TREE_ERROR_DIR); } - t->depth++; t->flags &= ~hasLstat; t->flags &= ~hasStat; t->basename = ".";