If lstat(2) fails, have bsdtar return a non-zero exit code if the

failed path is one which was specified on the command line.

This is a compromise between the situation prior to revision 1.57
(where a race between tar(1) and rm(1) could cause tar(1) to
spuriously report an error) and the situation after revision 1.57
(where "tar -c /no/such/path" prints a warning but returns with
an exit code of zero).

Inspired by:	rafan
MFC after:	1 week
This commit is contained in:
cperciva 2007-05-03 04:33:11 +00:00
parent e8c2f03327
commit 372e0ffbeb

View File

@ -649,6 +649,16 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
if (lst == NULL) {
/* Couldn't lstat(); must not exist. */
bsdtar_warnc(bsdtar, errno, "%s: Cannot stat", name);
/*
* Report an error via the exit code if the failed
* path is a prefix of what the user provided via
* the command line. (Testing for string equality
* here won't work due to trailing '/' characters.)
*/
if (memcmp(name, path, strlen(name)) == 0)
bsdtar->return_value = 1;
continue;
}
if (S_ISLNK(lst->st_mode))