Subject: bug#34843: Bug report for coreutils-8.28 - `cp` creates hardlinks on the second call with `-u`

From: 冰柯 <[email-masked]>
Date: Wed, 13 Mar 2019 15:41:23 +0800 (CST)

Dear coreutils authors:
    Hi! I'm writing this to report a bug for `cp`. Actually I'm not sure if it is a bug, but it did something weird on my computer.
    The strange behavior was encountered when I tried to copy my files, in which there were a few hardlinks, into a FAT32 partition. At the first time, the command succeeded, and it then fails on the second call, 'cannot create hard link ......: Operation not permitted.'

    Well, let's see a situation (first try on an ext4 partition):

    First create two directories `src` and `dst`:
        $ mkdir src dst
    Then create a regular file under `src`, and create a hardlink of it (`first` => `second`):
        $ touch src/first
        $ ln src/first src/second
    Copy the files into `dst`:
        $ cp -v -u src/* dst/
          'src/first' -> 'dst/first'
          'src/second' -> 'dst/second'
    Using `ls` we can see the files under `src` are hardlinks, and files under `dst` are regular files:
        $ ls -l src/
          total 0
          -rw-rw-r-- 2 icyybk icyybk 0 Mar 13 14:59 first
          -rw-rw-r-- 2 icyybk icyybk 0 Mar 13 14:59 second
        $ ls -l dst/
          total 0
          -rw-rw-r-- 1 icyybk icyybk 0 Mar 13 15:03 first
          -rw-rw-r-- 1 icyybk icyybk 0 Mar 13 15:03 second
    Then, run `cp` again:
        $ cp -v -u src/* dst/
          removed 'dst/second'
        $ ls -l dst/
          total 0
          -rw-rw-r-- 2 icyybk icyybk 0 Mar 13 15:03 first
          -rw-rw-r-- 2 icyybk icyybk 0 Mar 13 15:03 second
    It appears that, during a second call, something weird happened, the two files under `dst` changed into hardlinks.
    There's no error outputs in this situation, for the ext4 partition is used. But when a FAT32 partition is mounted on directory `dst`, the second call will fail with output:
      cp: cannot create hard link 'dst/second' to 'dst/first': Operation not permitted

    Is there anything wrong with my commands? Hope not. I just felt strange about why they turned into hardlinks while in the first time they are regular files. Very sure I did not specify `--preserve=links`.
    I'm now using version 8.28 of coreutils. It's the currently newest version I could download using my ubuntu 18.04 lts. Hope this bug will be fixed, if it is a bug.
    Thanks for reading this email, and sorry for my 'not-very-good' English skills...
    Have a nice day.

                                                      Yours sincerely,
                                                           Icy.