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:
Colin Percival 2007-05-03 04:33:11 +00:00
parent 9310f22692
commit c85ac10468
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=169226

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))