[CentOS] [semi-OT] C7 Possible bug but I can't determine what tool has the problem

Wed Jan 15 16:18:03 UTC 2020
Alessandro Baggi <alessandro.baggi at gmail.com>

Hi all,

I'm writing a script that uses rsync to sync 2 dirs on C7.
I noticed a strange behaviour.

I have 2 dir: src and dest. In src dir I generate a testfile with "dd 
if=/dev/zero of=testfile bs=1M count=100" and when I run "du -h 
testfile" I get the correct result.
Then I sync src/ to dest/ using "rsync -avS  src/ dest/", all ok but 
when I run "du -h dest/testfile" I get 0 and if I run "du -b 
dest/testfile" I get the correct size in bytes.

I made several test to see what happens and noticed that removing -S 
(--sparse) from rsync command problem does not occour.
In another test, thinking about a problem on 0ed file, I tried file 
generation using /dev/urandom then /dev/zero and running rsync -avS the 
problem is disappeared.

This not seems to be a CentOS 7 related problem. I tried also on Fedora 
31 and get the same problem.


I wrote a simple bash script to replicate the  problem:

#!/bin/bash
mkdir src
mkdir dest
cd src
#dd if=/dev/urandom of=testfile bs=1M count=100
dd if=/dev/zero of=testfile bs=1M count=100
echo "src/testfile size:"
du -h testfile
du -b testfile
cd ..
rsync -avS  src/ dest/ > /dev/null
echo "dest/testfile size after rsync --sparse:"
du -h dest/testfile
du -b dest/testfile
rm -f dest/testfile
echo "dest/testfile size after rsync:"
rsync -av  src/ dest/ > /dev/null
du -h dest/testfile
du -b dest/testfile

There is a bug in rsync or in du or something else?

Thanks in advance.