blob: 6b8090c7bc6b32fc62efd7b32cbdff4ea77680ff [file] [log] [blame]
Jonathan Niederc5be9622011-02-22 17:07:01 -06001#!/bin/sh
2set -e
3
Anders Kaseorg6e2a98f2016-08-19 21:55:48 -04004#DEBHELPER#
5
Jonathan Nieder09f3f8c2013-07-06 16:19:09 -07006# /var/cache/git/ -> /var/lib/git/ transition
7if test "$1" = upgrade &&
Jonathan Nieder57d16992013-07-30 19:11:19 -07008 dpkg --compare-versions "$2" lt-nl '1:1.8.4~rc0-1'; then
Jonathan Nieder09f3f8c2013-07-06 16:19:09 -07009 mkdir -m 755 -p /var/lib/git
10 (
11 cd /var/lib/git
12 for target in ../../cache/git/*; do
Jonathan Niederf42d7452013-08-01 22:27:23 -070013 if ! test -L "$target" && ! test -e "$target"; then
14 continue
15 fi
16
Jonathan Nieder09f3f8c2013-07-06 16:19:09 -070017 link=${target#../../cache/git/}
18 if ! test -L "$link" && ! test -e "$link"; then
19 ln -s "$target" "$link"
20 fi
21 done
22 )
23fi
24
Jonathan Nieder7fe8f472013-08-01 22:51:38 -070025# A previous version of the /var/lib/git/ transition code
26# left behind a symlink '/var/lib/git/*' -> '../../cache/git/*'.
27if 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/*'
33 fi
34fi
35
Jonathan Niedereb2a0932011-10-15 06:57:14 -050036# 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.
43#
44# Replace the hard links with symlinks _before_ upgrading to
45# avoid trouble.
Jonathan Niederbffbd822012-01-04 19:11:36 -060046#
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.
Jonathan Niedereb2a0932011-10-15 06:57:14 -050050
51if test "$1" = upgrade &&
52 dpkg --compare-versions "$2" lt-nl '1:1.7.7-2'; then
Jonathan Niederbffbd822012-01-04 19:11:36 -060053 refinode=$(stat -c%i /usr/lib/git-core/git-add)
54
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
Jonathan Niedereb2a0932011-10-15 06:57:14 -050058 for f in /usr/lib/git-core/*; do
Jonathan Niederbffbd822012-01-04 19:11:36 -060059 test "$f" != /usr/lib/git-core/git &&
60 test "$f" != /usr/lib/git-core/git-add || continue
Jonathan Niedereb2a0932011-10-15 06:57:14 -050061 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
67fi