From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 855303858034 for ; Tue, 2 Mar 2021 10:10:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 855303858034 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A718CAAC5; Tue, 2 Mar 2021 10:10:28 +0000 (UTC) Date: Tue, 2 Mar 2021 11:10:27 +0100 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org Subject: [PATCH] Clean up temporary file in hardlink mode Message-ID: <20210302101025.GA23663@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Mar 2021 10:10:30 -0000 Hi, Consider an executable file with hardlinks a.out and b.out. When running dwz once: ... $ dwz -h a.out b.out ... a.out and b.out are updated, and remain hardlinks to the same file. But when running dwz once more, a.out and b.out remain unchanged, and a temporary file b.out.#dwz#.XXXXXX is left. This is caused by the fact that the code in function dwz that is intended to handle unchanged hardlinks is never triggered. It is guarded by a "resa[n].res == 1" condition, but res->res is set to 0 at the end of function dwz, irrespective of whether the file changed or not. Fix this by only setting res->res to 0 if the file changed. This makes test-case twice-multifile.sh fail, we'll deal with that in a seperate patch. Any comments? Thanks, - Tom Clean up temporary file in hardlink mode 2021-03-02 Tom de Vries PR dwz/24275 * dwz.c (dwz): Only set res->res to 0 if the file changed. * testsuite/dwz.tests/twice-hardlink.sh: Remove PR24275 workaround. --- dwz.c | 11 ++++++++--- testsuite/dwz.tests/twice-hardlink.sh | 5 ----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dwz.c b/dwz.c index 1d7d815..96f292d 100644 --- a/dwz.c +++ b/dwz.c @@ -15255,6 +15255,10 @@ remove_empty_pus (void) /* Helper structure for hardlink discovery. */ struct file_result { + /* -2: Already processed under different name. + -1: Ignore. + 0: Processed, changed. + 1: Processed, unchanged. */ int res; dev_t dev; ino_t ino; @@ -15315,7 +15319,7 @@ dwz (const char *file, const char *outfile, struct file_result *res, file); close (fd); res->res = -2; - return 1; + return 0; } /* If it changed, try to hardlink it again. */ if (resa[n].res == 0) @@ -15572,6 +15576,9 @@ dwz (const char *file, const char *outfile, struct file_result *res, if (write_dso (dso, outfile, &st, save_to_temp)) ret = 1; + else + res->res = 0; + if (unlikely (progress_p)) report_progress (); } @@ -15595,8 +15602,6 @@ dwz (const char *file, const char *outfile, struct file_result *res, close (fd); free (dso); - if (ret == 0) - res->res = 0; if (ret == 3) { ret = (outfile != NULL) ? 1 : 0; diff --git a/testsuite/dwz.tests/twice-hardlink.sh b/testsuite/dwz.tests/twice-hardlink.sh index 6ce5ee1..6bc0794 100644 --- a/testsuite/dwz.tests/twice-hardlink.sh +++ b/testsuite/dwz.tests/twice-hardlink.sh @@ -29,8 +29,3 @@ fi cmp 1 1.saved rm -f 1 1.saved 2 2.saved dwz.err - -if [ -f 2.#dwz#.* ]; then - echo "PR24275 workaround used" > dwz.info - rm -f 2.#dwz#.* -fi