summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2004-06-27 01:08:54 +0000
committerkientzle <kientzle@FreeBSD.org>2004-06-27 01:08:54 +0000
commit4731df16a26e51f2f571e0222cbf4aa767d23583 (patch)
treea0292e2cb8223353f471fc7db905e9f6f1e96d62
parentddb1bad6a35a7a69ac921f84ecd8dd66c69b4415 (diff)
downloadFreeBSD-src-4731df16a26e51f2f571e0222cbf4aa767d23583.zip
FreeBSD-src-4731df16a26e51f2f571e0222cbf4aa767d23583.tar.gz
Don't abort immediately on directory change errors.
Instead, display a warning, clean up, and let main() return the error. In particular, this means that chdir() problems won't leave broken archives, though they will prompt an error exit value.
-rw-r--r--usr.bin/tar/write.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c
index da88154..4c16ffa 100644
--- a/usr.bin/tar/write.c
+++ b/usr.bin/tar/write.c
@@ -349,9 +349,13 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
pending_dir = NULL;
- if (bsdtar->start_dir != NULL && chdir(bsdtar->start_dir))
- bsdtar_errc(bsdtar, 1, errno,
+ if (bsdtar->start_dir != NULL && chdir(bsdtar->start_dir)) {
+ bsdtar_warnc(bsdtar, errno,
"chdir(%s) failed", bsdtar->start_dir);
+ bsdtar->return_value = 1;
+ return;
+ }
+
if (bsdtar->names_from_file != NULL)
archive_names_from_file(bsdtar, a);
@@ -363,9 +367,12 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
if (*arg == '\0') {
bsdtar->argv++;
arg = *bsdtar->argv;
- if (arg == NULL)
- bsdtar_errc(bsdtar, 1, 0,
+ if (arg == NULL) {
+ bsdtar_warnc(bsdtar, 1, 0,
"Missing argument for -C");
+ bsdtar->return_value = 1;
+ return;
+ }
}
/*-
@@ -417,10 +424,13 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
if (pending_dir &&
(*arg != '/' || (*arg == '@' && arg[1] != '/'))) {
/* Handle a deferred -C */
- if (chdir(pending_dir))
- bsdtar_errc(bsdtar, 1, 0,
+ if (chdir(pending_dir)) {
+ bsdtar_warnc(bsdtar, 0,
"could not chdir to '%s'\n",
pending_dir);
+ bsdtar->return_value = 1;
+ return;
+ }
free(pending_dir);
pending_dir = NULL;
}
OpenPOWER on IntegriCloud