From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com
Subject: [PATCH] Clean up temporary file in hardlink mode
Date: Tue, 01 Jan 2019 00:00:00 -0000 [thread overview]
Message-ID: <20190302144853.GA27924@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 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.
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 <tdevries@suse.de>
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
next reply other threads:[~2019-03-02 14:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-01 0:00 Tom de Vries [this message]
2019-01-01 0:00 ` Tom de Vries
2021-03-02 10:10 Tom de Vries
2021-03-03 22:57 ` Mark Wielaard
2021-03-04 8:21 ` 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=20190302144853.GA27924@delia \
--to=tdevries@suse.de \
--cc=dwz@sourceware.org \
--cc=jakub@redhat.com \
/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).