From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [PATCH] Clean up temporary file in hardlink mode
Date: Tue, 2 Mar 2021 11:10:27 +0100 [thread overview]
Message-ID: <20210302101025.GA23663@delia> (raw)
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 <tdevries@suse.de>
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
next reply other threads:[~2021-03-02 10:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 10:10 Tom de Vries [this message]
2021-03-03 22:57 ` Mark Wielaard
2021-03-04 8:21 ` Tom de Vries
-- strict thread matches above, loose matches on Subject: below --
2019-01-01 0:00 Tom de Vries
2019-01-01 0:00 ` Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210302101025.GA23663@delia \
--to=tdevries@suse.de \
--cc=dwz@sourceware.org \
--cc=jakub@redhat.com \
--cc=mark@klomp.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).