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
1=== modified file 'debian/changelog'
2--- debian/changelog 2011-12-12 08:42:41 +0000
3+++ debian/changelog 2011-12-12 10:13:34 +0000
4@@ -1,8 +1,15 @@
5 pkgbinarymangler (110) UNRELEASED; urgency=low
6
7+ [ Martin Pitt ]
8 * pkgstripfiles: Log how many seconds the PNG optimization took.
9
10- -- Martin Pitt <martin.pitt@ubuntu.com> Mon, 12 Dec 2011 09:42:25 +0100
11+ [ Evan Broder ]
12+ * pkgstriptranslations: Use a copy of the code from dh_link to make sure
13+ pkgstriptranslations creates symlinks compliant with Debian
14+ Policy. (LP: #899520)
15+ * test/run: Adjust tests to expect relative symlinks.
16+
17+ -- Evan Broder <evan@ebroder.net> Mon, 12 Dec 2011 01:41:41 -0800
18
19 pkgbinarymangler (109) precise; urgency=low
20
21
22=== modified file 'pkgstriptranslations'
23--- pkgstriptranslations 2011-11-15 14:24:07 +0000
24+++ pkgstriptranslations 2011-12-12 10:13:34 +0000
25@@ -4,6 +4,58 @@
26
27 . ${PKGBINARYMANGLER_COMMON_PATH:-/usr/share/pkgbinarymangler}/common
28
29+compliant_symlink() {
30+ # Shell port of lines 184-222 of dh_link from debhelper
31+ # 8.9.0ubuntu1
32+ #
33+ # This function must be called from the top-level of the package
34+ local tmp src dest src_dirs dest_dirs x i
35+
36+ src="$(echo "$1" | sed -e 's,/+,/,g; s,^/,,')"
37+ dest="$(echo "$2" | sed -e 's,/+,/,g; s,^/,,')"
38+
39+ # Make sure the directory the link will be in exists
40+ mkdir -p "$(dirname "$dest")"
41+
42+ # Policy says that if the link is all within one toplevel
43+ # directory, it should be relative. If it's between top level
44+ # directories, leave it absolute.
45+ IFS="/" read -ra src_dirs <<< "$src"
46+ IFS="/" read -ra dest_dirs <<< "$dest"
47+
48+ if [ ${#src_dirs[@]} -gt 0 ] && [ "${src_dirs[0]}" = "${dest_dirs[0]}" ]; then
49+ # Figure out how much of a path $src and $dest share in common
50+ for (( x = 0; x < ${#src_dirs[@]}; x++ )); do
51+ [ "${src_dirs[$x]}" = "${dest_dirs[$x]}" ] || break
52+ done
53+
54+ # Build up the new src
55+ src=""
56+ # Note: use of < and not <= is deliberate here - the Perl
57+ # version used $#dest_dirs, which is "the index of dest_dirs'
58+ # last element" - i.e. length minus 1
59+ for (( i = 1; i < (${#dest_dirs[@]} - x); i++ )); do
60+ src="${src}../"
61+ done
62+ for (( i = x; i < ${#src_dirs[@]}; i++ )); do
63+ src="${src}${src_dirs[$i]}/"
64+ done
65+ if [ $x -gt ${#src_dirs[@]} ] && [ "$src" = "" ]; then
66+ src="." # special case
67+ fi
68+ src="${src%/}"
69+ else
70+ # Make sure it's properly absolute
71+ src="/$src"
72+ fi
73+
74+ if [ -d "$dest" ] && ! [ -L "$dest" ]; then
75+ echo "pkgstriptranslations: link destination $dest is a directory"
76+ fi
77+ rm -f "$dest"
78+ ln -sf "$src" "$dest"
79+}
80+
81 # strip translations from .desktop files if they have a gettext domain (since
82 # inline translations are preferred)
83 desktop_files()
84@@ -66,10 +118,9 @@
85 pushd "$PKGDIR" >/dev/null
86 (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
87 install -D -m 644 "$f" "$tmp/_static/$PKGNAME/$f"
88- rm "$f"
89 dest=${f/gnome\/help/gnome\/help-langpack}
90 dest=${dest/share\/omf/share\/omf-langpack}
91- ln -s "/$dest" "$f"
92+ compliant_symlink "$dest" "$f"
93 [ ! -f DEBIAN/md5sums ] || sed -i "\& $f$&d" DEBIAN/md5sums
94 done
95 popd >/dev/null
96@@ -116,9 +167,8 @@
97 pushd "$PKGDIR" >/dev/null
98 find usr/share/help -type f ! -wholename '*/C/*' | while read f; do
99 install -D -m 644 "$f" "$tmp/_static/$PKGNAME/$f"
100- rm "$f"
101 dest=${f/share\/help/share\/help-langpack}
102- ln -s "/$dest" "$f"
103+ compliant_symlink "$dest" "$f"
104 [ ! -f DEBIAN/md5sums ] || sed -i "\& $f$&d" DEBIAN/md5sums
105 done
106 popd >/dev/null
107
108=== modified file 'test/run'
109--- test/run 2011-11-29 09:18:32 +0000
110+++ test/run 2011-12-12 10:13:34 +0000
111@@ -1026,9 +1026,9 @@
112
113 # translated de will be replaced with symlink to langpack
114 self.assertEqual(c['vanilla']['./usr/share/gnome/help/vanilla/de/index.html']['linkto'],
115- '/usr/share/gnome/help-langpack/vanilla/de/index.html')
116+ '../../../help-langpack/vanilla/de/index.html')
117 self.assertEqual(c['vanilla']['./usr/share/gnome/help/vanilla/de/figures/main.png']['linkto'],
118- '/usr/share/gnome/help-langpack/vanilla/de/figures/main.png')
119+ '../../../../help-langpack/vanilla/de/figures/main.png')
120
121 # untranslated es will be replace with a symlink to C file
122 self.assertEqual(c['vanilla']['./usr/share/gnome/help/vanilla/es/index.html']['linkto'],
123@@ -1092,9 +1092,9 @@
124
125 # translated de will be replaced with symlink to langpack
126 self.assertEqual(c['vanilla']['./usr/share/help/de/vanilla/index.page']['linkto'],
127- '/usr/share/help-langpack/de/vanilla/index.page')
128+ '../../../help-langpack/de/vanilla/index.page')
129 self.assertEqual(c['vanilla']['./usr/share/help/de/vanilla/figures/main.png']['linkto'],
130- '/usr/share/help-langpack/de/vanilla/figures/main.png')
131+ '../../../../help-langpack/de/vanilla/figures/main.png')
132
133 # untranslated es will be replace with a symlink to C file
134 self.assertEqual(c['vanilla']['./usr/share/help/es/vanilla/index.page']['linkto'],

Subscribers

People subscribed via source and target branches

to all changes: