From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 125473 invoked by alias); 8 Mar 2019 11:33:54 -0000 Mailing-List: contact dwz-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: dwz-owner@sourceware.org Received: (qmail 125457 invoked by uid 89); 8 Mar 2019 11:33:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy=beneficial, Processed X-Spam-Status: No, score=-26.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-HELO: mx1.suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Subject: Re: [PATCH] Clean up temporary file in hardlink mode From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com References: <20190302144853.GA27924@delia> Message-ID: <5a567155-2509-fdb2-6699-fadcd01c111c@suse.de> Date: Tue, 01 Jan 2019 00:00:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <20190302144853.GA27924@delia> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-SW-Source: 2019-q1/txt/msg00106.txt.bz2 On 02-03-19 15:48, Tom de Vries wrote: > 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 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. > To put it in terms of the --trace switch I just posted, the effect of the patch is: ... $ dwz -t -h a.out b.out Compressing a.out Updating hardlink b.out to changed file $ dwz -t -h a.out b.out Compressing a.out dwz: a.out: compression not beneficial - old size 3444 new size 3444 -Updating hardlink b.out to changed file +Skipping hardlink b.out to unchanged file ... Thanks, - Tom > OK for trunk? > > [ Applies on top of trunk + "[PATCH] Don't process low-mem files in multifile > mode". ] > > Thanks, > - Tom > > Clean up temporary file in hardlink mode > > 2019-03-02 Tom de Vries > > PR dwz/24275 > * dwz.c (struct file_result): Document res field. > (dwz): Only set res->res to 1 if changed. > * testsuite/dwz.tests/hardlink-no-change.sh: New test. > > --- > dwz.c | 9 +++++++-- > testsuite/dwz.tests/hardlink-no-change.sh | 23 +++++++++++++++++++++++ > 2 files changed, 30 insertions(+), 2 deletions(-) > > diff --git a/dwz.c b/dwz.c > index ffa8e08..3673bbf 100644 > --- a/dwz.c > +++ b/dwz.c > @@ -10950,6 +10950,11 @@ 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; > @@ -11206,6 +11211,8 @@ dwz (const char *file, const char *outfile, struct file_result *res, > > if (write_dso (dso, outfile, &st)) > ret = 1; > + else > + res->res = 0; > } > } > > @@ -11227,8 +11234,6 @@ dwz (const char *file, const char *outfile, struct file_result *res, > close (fd); > > free (dso); > - if (ret == 0) > - res->res = 0; > return ret; > } > > diff --git a/testsuite/dwz.tests/hardlink-no-change.sh b/testsuite/dwz.tests/hardlink-no-change.sh > new file mode 100755 > index 0000000..945d220 > --- /dev/null > +++ b/testsuite/dwz.tests/hardlink-no-change.sh > @@ -0,0 +1,23 @@ > +#!/bin/sh > + > +set -e > + > +cp ../hello 1 > +ln 1 2 > + > +dwz -h 1 2 > + > +dwz -h 1 2 2>/dev/null > + > +smaller-than.sh 1 ../hello > +smaller-than.sh 2 ../hello > + > +hl="$(find -samefile 1)" > +hl="$(echo $hl)" > +[ "$hl" = "./1 ./2" ] > + > +ls=$(ls) > +ls=$(echo $ls) > +[ "$ls" = "1 2" ] > + > +rm -f 1 2 >