]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hardlink: fix 0-sized file processing
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Mon, 28 Oct 2024 18:19:34 +0000 (19:19 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 31 Oct 2024 08:43:52 +0000 (09:43 +0100)
The manual says that -s0 will process 0-sized files normally,
but as it stands (a) hardlink considers 0-sized files unlinkable
(so, with -l, unlistable) and (b) fileeq considers reading an empty
prologue to be an error

lib/fileeq.c
misc-utils/hardlink.c

index b40eba2b0b400e9fa55b9587b865c4ef6acd9d1a..1f7f90ccb5c10015fb97c6812a210ff8259320d1 100644 (file)
@@ -465,7 +465,7 @@ static ssize_t get_intro(struct ul_fileeq *eq, struct ul_fileeq_data *data,
                        return -1;
                rsz = read_all(fd, (char *) data->intro, sizeof(data->intro));
                DBG(DATA, ul_debugobj(data, " read %zu bytes intro", sizeof(data->intro)));
-               if (rsz <= 0)
+               if (rsz < 0)
                        return -1;
                data->nblocks = 1;
        }
index 643df7cf24b5852cf362f0ef9d74275c9e528745..8c5f24aad7cc6ff003514438b3a95736e175b1d6 100644 (file)
@@ -649,8 +649,7 @@ static int file_xattrs_equal(const struct file *a, const struct file *b)
  */
 static int file_may_link_to(const struct file *a, const struct file *b)
 {
-       return (a->st.st_size != 0 &&
-               a->st.st_size == b->st.st_size &&
+       return (a->st.st_size == b->st.st_size &&
                a->links != NULL && b->links != NULL &&
                a->st.st_dev == b->st.st_dev &&
                a->st.st_ino != b->st.st_ino &&