1

Just tripped across a weird case of du. Putting arguments one way gives:

$ du -s htdocs/.git/ feuerkraft/.git/ media/.git/
40564   htdocs/.git/
40740   feuerkraft/.git/
204 media/.git/

Putting them in a different order changes the size of the last directory:

$ du -s media/.git/ htdocs/.git/ feuerkraft/.git/ 
40696   media/.git/
40564   htdocs/.git/
248 feuerkraft/.git/

Those should all be regular directories:

$ ls -l */.git -d -i
4891918 drwxrwxr-x 1 ingo ingo 138 Mar 28 08:41 feuerkraft/.git
4892896 drwxrwxr-x 1 ingo ingo 138 Mar 28 08:44 htdocs/.git
4893874 drwxrwxr-x 1 ingo ingo 138 Mar 28 08:42 media/.git

Doing it manually gives:

$ for i in htdocs/.git/ feuerkraft/.git/ media/.git/; do du -s "${i}"; done
40564   htdocs/.git/
40740   feuerkraft/.git/
40696   media/.git/

When I copy the directory with cp -axv the problem stays, if I copy the directory with cp -rxv it disappears.

Digging deeper:

$ du -s feuerkraft/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack media/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack htdocs/.git/objects/pack/pack-31a80589fbb132827d19b718c07aba1aa6bb9c02.pack  | wc -l
2
$ ls feuerkraft/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack media/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack htdocs/.git/objects/pack/pack-31a80589fbb132827d19b718c07aba1aa6bb9c02.pack  | wc -l 
3

du list only 2 files if three are given, ls lists 3.

Filesystem is btrfs. Is this a bug or something with compression/copy-on-write or whatever?

1
  • I think it is a bug, because there is no reason why the file size should be different(unless they are being modified at the same time). You should file it to concerned developers. Mar 28, 2015 at 8:05

1 Answer 1

0

This explains it:

$ ls -l feuerkraft/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack media/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack htdocs/.git/objects/pack/pack-31a80589fbb132827d19b718c07aba1aa6bb9c02.pack -i
13150428 -r--r--r-- 2 ingo ingo 41191354 Mar 15 14:14 feuerkraft/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack
13151244 -r--r--r-- 1 ingo ingo 41197513 Mar 28 08:44 htdocs/.git/objects/pack/pack-31a80589fbb132827d19b718c07aba1aa6bb9c02.pack
13150428 -r--r--r-- 2 ingo ingo 41191354 Mar 15 14:14 media/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack

The feuerkraft and media files point to the same inode, i.e. hard links. This is a feature of git clone and documented in the manpage:

$ man git clone
...
   --no-hardlinks
       Force the cloning process from a repository on a local filesystem to copy
       the files under the .git/objects directory instead of using hardlinks.
       This may be desirable if you are trying to make a back-up of your
       repository.

This also explains why git sets the pack files to read-only, always wondered about that. du also has an option to count hard links double:

$ man du
...
   -l, --count-links
          count sizes many times if hard linked

And that gives the expected results:

$ du -ls media/.git/ htdocs/.git/ feuerkraft/.git/
40696   media/.git/
40564   htdocs/.git/
40740   feuerkraft/.git/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .