debian/rules: Split override_dh_installdocs into -arch and -indep parts
[git/debian.git] / debian / git.preinst
blob6b8090c7bc6b32fc62efd7b32cbdff4ea77680ff
1 #!/bin/sh
2 set -e
4 #DEBHELPER#
6 # /var/cache/git/ -> /var/lib/git/ transition
7 if test "$1" = upgrade &&
8 dpkg --compare-versions "$2" lt-nl '1:1.8.4~rc0-1'; then
9 mkdir -m 755 -p /var/lib/git
11 cd /var/lib/git
12 for target in ../../cache/git/*; do
13 if ! test -L "$target" && ! test -e "$target"; then
14 continue
17 link=${target#../../cache/git/}
18 if ! test -L "$link" && ! test -e "$link"; then
19 ln -s "$target" "$link"
21 done
25 # A previous version of the /var/lib/git/ transition code
26 # left behind a symlink '/var/lib/git/*' -> '../../cache/git/*'.
27 if test "$1" = upgrade &&
28 dpkg --compare-versions "$2" eq '1:1.8.4~rc0-1' &&
29 test -L '/var/lib/git/*'; then
30 target=$(readlink '/var/lib/git/*')
31 if test "$target" = '../../cache/git/*'; then
32 rm -f '/var/lib/git/*'
36 # Git versions before 1.7.7-2 kept about 100 hard links to
37 # /usr/lib/git-core/git at /usr/lib/git-core/git-* to avoid
38 # wasting time resolving a symlink when old scripts call "git
39 # foo" as git-foo. Btrfs doesn't like to have more than 130 or
40 # so links to a single inode in a given directory. dpkg versions
41 # 1.16.1 and later temporarily double the number of hard links to
42 # an inode when upgrading a package.
44 # Replace the hard links with symlinks _before_ upgrading to
45 # avoid trouble.
47 # For added fun, coreutils mv will not replace a file by a
48 # symlink to the same inode (bug #654666). We give
49 # /usr/lib/git-core/git its own inode to work around that.
51 if test "$1" = upgrade &&
52 dpkg --compare-versions "$2" lt-nl '1:1.7.7-2'; then
53 refinode=$(stat -c%i /usr/lib/git-core/git-add)
55 rm -f /usr/lib/git-core/git.tmp
56 cp -p /usr/lib/git-core/git /usr/lib/git-core/git.tmp
57 mv -f /usr/lib/git-core/git.tmp /usr/lib/git-core/git
58 for f in /usr/lib/git-core/*; do
59 test "$f" != /usr/lib/git-core/git &&
60 test "$f" != /usr/lib/git-core/git-add || continue
61 rm -f "$f.tmp"
62 inode=$(stat -c%i "$f")
63 test "$inode" = "$refinode" || continue
64 ln -s git "$f.tmp"
65 mv -f "$f.tmp" "$f"
66 done