Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/compress uncompress: if the source doesn't exist, do...
details: https://anonhg.NetBSD.org/src/rev/75b591890195
branches: trunk
changeset: 366358:75b591890195
user: rillig <rillig%NetBSD.org@localhost>
date: Sun May 22 21:16:50 2022 +0000
description:
uncompress: if the source doesn't exist, don't touch the target
Fixes part of PR bin/19722, reported by Giorgos Keramidas.
diffstat:
tests/usr.bin/compress/t_pr_19722.sh | 16 ++++++++++------
usr.bin/compress/compress.c | 12 ++++++------
2 files changed, 16 insertions(+), 12 deletions(-)
diffs (88 lines):
diff -r 90c73efb29ea -r 75b591890195 tests/usr.bin/compress/t_pr_19722.sh
--- a/tests/usr.bin/compress/t_pr_19722.sh Sun May 22 20:49:12 2022 +0000
+++ b/tests/usr.bin/compress/t_pr_19722.sh Sun May 22 21:16:50 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_pr_19722.sh,v 1.2 2022/05/22 20:49:12 rillig Exp $
+# $NetBSD: t_pr_19722.sh,v 1.3 2022/05/22 21:16:50 rillig Exp $
#
# Copyright (c) 2022 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -92,15 +92,17 @@
uncompress_no_source_no_target_body()
{
# PR 19722: uncompressing a missing source creates empty target
+ #
+ # Before compress.c 1.28 from 2022-05-22, uncompress created an empty
+ # target file and didn't clean it up.
atf_check \
-s 'not-exit:0' \
-e 'inline:uncompress: file.Z: No such file or directory\n' \
uncompress -f file
- # FIXME: The target file must not be created.
- atf_check cat file
- atf_check test ! -f nonexistent.Z
+ atf_check test ! -f file
+ atf_check test ! -f file.Z
}
@@ -108,6 +110,9 @@
uncompress_no_source_existing_target_body()
{
# PR 19722: uncompressing a missing source truncates target
+ #
+ # Before compress.c 1.28 from 2022-05-22, uncompress truncated the
+ # target.
atf_check sh -c "echo 'hello' > file"
@@ -116,8 +121,7 @@
-e 'inline:uncompress: file.Z: No such file or directory\n' \
uncompress -f file
- # FIXME: The file must not be truncated.
- atf_check cat file
+ atf_check -o 'inline:hello\n' cat file
atf_check test ! -f file.Z
}
diff -r 90c73efb29ea -r 75b591890195 usr.bin/compress/compress.c
--- a/usr.bin/compress/compress.c Sun May 22 20:49:12 2022 +0000
+++ b/usr.bin/compress/compress.c Sun May 22 21:16:50 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compress.c,v 1.27 2022/05/22 19:41:49 rillig Exp $ */
+/* $NetBSD: compress.c,v 1.28 2022/05/22 21:16:50 rillig Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)compress.c 8.2 (Berkeley) 1/7/94";
#else
-__RCSID("$NetBSD: compress.c,v 1.27 2022/05/22 19:41:49 rillig Exp $");
+__RCSID("$NetBSD: compress.c,v 1.28 2022/05/22 21:16:50 rillig Exp $");
#endif
#endif /* not lint */
@@ -313,15 +313,15 @@
oreg = 0;
ifp = ofp = NULL;
- if ((ofp = fopen(out, "w")) == NULL) {
- cwarn("%s", out);
- return;
- }
if ((ifp = zopen(in, "r", bits)) == NULL) {
cwarn("%s", in);
goto err;
}
+ if ((ofp = fopen(out, "w")) == NULL) {
+ cwarn("%s", out);
+ goto err;
+ }
if (!isstdin) {
if (stat(in, &sb)) {
cwarn("%s", in);
Home |
Main Index |
Thread Index |
Old Index