Merge lp:~broder/ubuntu/precise/pkgbinarymangler/relative-symlinks-899520 into lp:ubuntu/precise/pkgbinarymangler

Proposed by Evan Broder
Status: Merged
Merged at revision: 228
Proposed branch: lp:~broder/ubuntu/precise/pkgbinarymangler/relative-symlinks-899520
Merge into: lp:ubuntu/precise/pkgbinarymangler
Diff against target: 134 lines (+66/-9)
3 files modified
debian/changelog (+8/-1)
pkgstriptranslations (+54/-4)
test/run (+4/-4)
To merge this branch: bzr merge lp:~broder/ubuntu/precise/pkgbinarymangler/relative-symlinks-899520
Reviewer Review Type Date Requested Status
Martin Pitt Approve
Review via email: mp+85308@code.launchpad.net

Description of the change

This merge adds a helper function for generating Policy-compliant symlinks to pkgstriptranslations and then uses it when creating the gnome-help and mallard langpack symlinks.

The original merge was right, but only by accident.

I used "<" instead of "<=" in two of the for loops. It turns out, though, that dh_link was using the $# sigil, which means "the index of the last element of the array" - i.e. "length minus 1", so "<" instead of "<=" is actually correct. Now that I've fulfilled my daily quotient of Perl insanity, I added a comment so that other people could follow along.

On further investigation, I realized the symlinks it was generating were right. Because the foo -> foo-langpack symlinks are between files at the same hierarchy level, you can verify that the symlinks are correct by noting that the number of ".." entries in the path is the same as the number of non-".." entries.

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

Thank you!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2011-12-12 08:42:41 +0000
+++ debian/changelog 2011-12-12 10:13:34 +0000
@@ -1,8 +1,15 @@
1pkgbinarymangler (110) UNRELEASED; urgency=low1pkgbinarymangler (110) UNRELEASED; urgency=low
22
3 [ Martin Pitt ]
3 * pkgstripfiles: Log how many seconds the PNG optimization took.4 * pkgstripfiles: Log how many seconds the PNG optimization took.
45
5 -- Martin Pitt <martin.pitt@ubuntu.com> Mon, 12 Dec 2011 09:42:25 +01006 [ Evan Broder ]
7 * pkgstriptranslations: Use a copy of the code from dh_link to make sure
8 pkgstriptranslations creates symlinks compliant with Debian
9 Policy. (LP: #899520)
10 * test/run: Adjust tests to expect relative symlinks.
11
12 -- Evan Broder <evan@ebroder.net> Mon, 12 Dec 2011 01:41:41 -0800
613
7pkgbinarymangler (109) precise; urgency=low14pkgbinarymangler (109) precise; urgency=low
815
916
=== modified file 'pkgstriptranslations'
--- pkgstriptranslations 2011-11-15 14:24:07 +0000
+++ pkgstriptranslations 2011-12-12 10:13:34 +0000
@@ -4,6 +4,58 @@
44
5. ${PKGBINARYMANGLER_COMMON_PATH:-/usr/share/pkgbinarymangler}/common5. ${PKGBINARYMANGLER_COMMON_PATH:-/usr/share/pkgbinarymangler}/common
66
7compliant_symlink() {
8 # Shell port of lines 184-222 of dh_link from debhelper
9 # 8.9.0ubuntu1
10 #
11 # This function must be called from the top-level of the package
12 local tmp src dest src_dirs dest_dirs x i
13
14 src="$(echo "$1" | sed -e 's,/+,/,g; s,^/,,')"
15 dest="$(echo "$2" | sed -e 's,/+,/,g; s,^/,,')"
16
17 # Make sure the directory the link will be in exists
18 mkdir -p "$(dirname "$dest")"
19
20 # Policy says that if the link is all within one toplevel
21 # directory, it should be relative. If it's between top level
22 # directories, leave it absolute.
23 IFS="/" read -ra src_dirs <<< "$src"
24 IFS="/" read -ra dest_dirs <<< "$dest"
25
26 if [ ${#src_dirs[@]} -gt 0 ] && [ "${src_dirs[0]}" = "${dest_dirs[0]}" ]; then
27 # Figure out how much of a path $src and $dest share in common
28 for (( x = 0; x < ${#src_dirs[@]}; x++ )); do
29 [ "${src_dirs[$x]}" = "${dest_dirs[$x]}" ] || break
30 done
31
32 # Build up the new src
33 src=""
34 # Note: use of < and not <= is deliberate here - the Perl
35 # version used $#dest_dirs, which is "the index of dest_dirs'
36 # last element" - i.e. length minus 1
37 for (( i = 1; i < (${#dest_dirs[@]} - x); i++ )); do
38 src="${src}../"
39 done
40 for (( i = x; i < ${#src_dirs[@]}; i++ )); do
41 src="${src}${src_dirs[$i]}/"
42 done
43 if [ $x -gt ${#src_dirs[@]} ] && [ "$src" = "" ]; then
44 src="." # special case
45 fi
46 src="${src%/}"
47 else
48 # Make sure it's properly absolute
49 src="/$src"
50 fi
51
52 if [ -d "$dest" ] && ! [ -L "$dest" ]; then
53 echo "pkgstriptranslations: link destination $dest is a directory"
54 fi
55 rm -f "$dest"
56 ln -sf "$src" "$dest"
57}
58
7# strip translations from .desktop files if they have a gettext domain (since59# strip translations from .desktop files if they have a gettext domain (since
8# inline translations are preferred)60# inline translations are preferred)
9desktop_files()61desktop_files()
@@ -66,10 +118,9 @@
66 pushd "$PKGDIR" >/dev/null118 pushd "$PKGDIR" >/dev/null
67 (find usr/share/gnome/help -type f ! -wholename '*/C/*'; [ ! -d usr/share/omf ] || find usr/share/omf -type f -name '*.omf' ! -name '*-C.omf') | while read f; do119 (find usr/share/gnome/help -type f ! -wholename '*/C/*'; [ ! -d usr/share/omf ] || find usr/share/omf -type f -name '*.omf' ! -name '*-C.omf') | while read f; do
68 install -D -m 644 "$f" "$tmp/_static/$PKGNAME/$f"120 install -D -m 644 "$f" "$tmp/_static/$PKGNAME/$f"
69 rm "$f"
70 dest=${f/gnome\/help/gnome\/help-langpack}121 dest=${f/gnome\/help/gnome\/help-langpack}
71 dest=${dest/share\/omf/share\/omf-langpack}122 dest=${dest/share\/omf/share\/omf-langpack}
72 ln -s "/$dest" "$f"123 compliant_symlink "$dest" "$f"
73 [ ! -f DEBIAN/md5sums ] || sed -i "\& $f$&d" DEBIAN/md5sums124 [ ! -f DEBIAN/md5sums ] || sed -i "\& $f$&d" DEBIAN/md5sums
74 done125 done
75 popd >/dev/null126 popd >/dev/null
@@ -116,9 +167,8 @@
116 pushd "$PKGDIR" >/dev/null167 pushd "$PKGDIR" >/dev/null
117 find usr/share/help -type f ! -wholename '*/C/*' | while read f; do168 find usr/share/help -type f ! -wholename '*/C/*' | while read f; do
118 install -D -m 644 "$f" "$tmp/_static/$PKGNAME/$f"169 install -D -m 644 "$f" "$tmp/_static/$PKGNAME/$f"
119 rm "$f"
120 dest=${f/share\/help/share\/help-langpack}170 dest=${f/share\/help/share\/help-langpack}
121 ln -s "/$dest" "$f"171 compliant_symlink "$dest" "$f"
122 [ ! -f DEBIAN/md5sums ] || sed -i "\& $f$&d" DEBIAN/md5sums172 [ ! -f DEBIAN/md5sums ] || sed -i "\& $f$&d" DEBIAN/md5sums
123 done173 done
124 popd >/dev/null174 popd >/dev/null
125175
=== modified file 'test/run'
--- test/run 2011-11-29 09:18:32 +0000
+++ test/run 2011-12-12 10:13:34 +0000
@@ -1026,9 +1026,9 @@
10261026
1027 # translated de will be replaced with symlink to langpack1027 # translated de will be replaced with symlink to langpack
1028 self.assertEqual(c['vanilla']['./usr/share/gnome/help/vanilla/de/index.html']['linkto'],1028 self.assertEqual(c['vanilla']['./usr/share/gnome/help/vanilla/de/index.html']['linkto'],
1029 '/usr/share/gnome/help-langpack/vanilla/de/index.html')1029 '../../../help-langpack/vanilla/de/index.html')
1030 self.assertEqual(c['vanilla']['./usr/share/gnome/help/vanilla/de/figures/main.png']['linkto'],1030 self.assertEqual(c['vanilla']['./usr/share/gnome/help/vanilla/de/figures/main.png']['linkto'],
1031 '/usr/share/gnome/help-langpack/vanilla/de/figures/main.png')1031 '../../../../help-langpack/vanilla/de/figures/main.png')
10321032
1033 # untranslated es will be replace with a symlink to C file1033 # untranslated es will be replace with a symlink to C file
1034 self.assertEqual(c['vanilla']['./usr/share/gnome/help/vanilla/es/index.html']['linkto'],1034 self.assertEqual(c['vanilla']['./usr/share/gnome/help/vanilla/es/index.html']['linkto'],
@@ -1092,9 +1092,9 @@
10921092
1093 # translated de will be replaced with symlink to langpack1093 # translated de will be replaced with symlink to langpack
1094 self.assertEqual(c['vanilla']['./usr/share/help/de/vanilla/index.page']['linkto'],1094 self.assertEqual(c['vanilla']['./usr/share/help/de/vanilla/index.page']['linkto'],
1095 '/usr/share/help-langpack/de/vanilla/index.page')1095 '../../../help-langpack/de/vanilla/index.page')
1096 self.assertEqual(c['vanilla']['./usr/share/help/de/vanilla/figures/main.png']['linkto'],1096 self.assertEqual(c['vanilla']['./usr/share/help/de/vanilla/figures/main.png']['linkto'],
1097 '/usr/share/help-langpack/de/vanilla/figures/main.png')1097 '../../../../help-langpack/de/vanilla/figures/main.png')
10981098
1099 # untranslated es will be replace with a symlink to C file1099 # untranslated es will be replace with a symlink to C file
1100 self.assertEqual(c['vanilla']['./usr/share/help/es/vanilla/index.page']['linkto'],1100 self.assertEqual(c['vanilla']['./usr/share/help/es/vanilla/index.page']['linkto'],

Subscribers

People subscribed via source and target branches

to all changes: