Package: debhelper Version: 8.0.0 Severity: wishlist Tags: patch -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
Hi This would assist people programming debhelper-like utilities to make policy compliant symlinks without needing to invoke or copying code from dh_link. ~Niels - -- System Information: Debian Release: 6.0 APT prefers testing APT policy: (990, 'testing'), (500, 'unstable'), (1, 'experimental') Architecture: i386 (i686) Kernel: Linux 2.6.32-5-686 (SMP w/2 CPU cores) Locale: LANG=en_DK.UTF-8, LC_CTYPE=en_DK.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages debhelper depends on: ii binutils 2.20.1-15 The GNU assembler, linker and bina ii dpkg-dev 1.15.8.7 Debian package development tools ii file 5.04-5 Determines file type using "magic" ii html2text 1.3.2a-15 advanced HTML to text converter ii man-db 2.5.7-8 on-line manual pager ii perl 5.10.1-17 Larry Wall's Practical Extraction ii perl-base 5.10.1-17 minimal Perl system ii po-debconf 1.0.16+nmu1 tool for managing templates file t debhelper recommends no packages. Versions of packages debhelper suggests: pn dh-make <none> (no description available) - -- no debconf information -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBCAAGBQJNMgcdAAoJEAVLu599gGRCCRoP/3pdacd8ttU0f3Z0eJ1oZE+s jS4IOTFcH9rDcfFePwxZZe89PuBPi9nlyM+aN9V/ukadqVBeStemK4xs3fGAr7uI cwNY4kuErb186Jl0tvOjD2Iu71/DXsGBhnOHV5llx6gQ63w3VKUPvPFZhbCB9Wao ITy6bN4a5sEjQZAwUmnUIEq1Ty5wKPBLxABByZrLITbCsw2svC3T3MMVDPZRR5On AfX+MFZj4oNG86Z/pnYxNL5weMpVqX/ddPziUnjFSRaAAv0dHeuIR8E34maozwQF dyH0VnfsQUCH9fejAKEDN9QJY+Eo2gWTgonWqAEE15OtozM1hRU9InwOL6H9dDGZ vhiEmDK/Q0V1Ko1Nd+KjQ8wY3+04u6LZ86gyBI+ZEXufwTkc8kMqUGT8KP6cg6M3 qaTidQRBFe/QklMvdRuFs/PGdFzcNs9N9mxo7xFlbqCPCGz2jO6fIj3rUJVQULme 9buZOtCvfy7ej7pXLxdxsE+0hGyCzVWaXdI9IkNoCgthPbCUg8h57EvLbbyFcyK7 qqnMZiwCHUO/nB86AJ6kw11yQW8iEeQV/TEwLRYLQ6Ay1pfEB21dAPiyjneEtqRh Mv+RzrBVAzOmpLF0fqZnSv1Gzwz0RuTC8gHo/S0V5SJZmkEEAvnzdHRQ6iQbu2FA XhHLq0or3r1Ng4tzmMZk =OEv1 -----END PGP SIGNATURE-----
>From fe0157d6214cb335d09b8ba486d06a78a6e914b9 Mon Sep 17 00:00:00 2001 From: Niels Thykier <ni...@thykier.net> Date: Sat, 15 Jan 2011 21:38:27 +0100 Subject: [PATCH] Added make_symlink to create Policy compliant symlinks --- Debian/Debhelper/Dh_Lib.pm | 94 +++++++++++++++++++++++++++++++++++++++++++- dh_link | 87 +--------------------------------------- doc/PROGRAMMING | 4 ++ 3 files changed, 99 insertions(+), 86 deletions(-) diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm index fb83480..86b4f0e 100644 --- a/Debian/Debhelper/Dh_Lib.pm +++ b/Debian/Debhelper/Dh_Lib.pm @@ -16,7 +16,7 @@ use vars qw(@ISA @EXPORT %dh); &compat &addsubstvar &delsubstvar &excludefile &package_arch &is_udeb &udeb_filename &debhelper_script_subst &escape_shell &inhibit_log &load_log &write_log &dpkg_architecture_value - &sourcepackage + &sourcepackage &make_symlink &is_make_jobserver_unavailable &clean_jobserver_makeflags); my $max_compat=8; @@ -830,6 +830,98 @@ sub debhelper_script_subst { } } + +# symlink($dest, $src[, $tmp]) creates a symlink from $dest -> $src. +# if $tmp is given, $dest will be created in $base. +# Usually $tmp should be the value of tmpdir($package); +sub make_symlink{ + my $dest = shift; + my $src = _expand_path(shift); + my $tmp = shift//''; + $src=~s:^/::; + $dest=~s:^/::; + + if ($src eq $dest) { + warning("skipping link from $src to self"); + return; + } + + # Make sure the directory the link will be in exists. + my $basedir=dirname("$tmp/$dest"); + if (! -e $basedir) { + doit("install","-d",$basedir); + } + + # Policy says that if the link is all within one toplevel + # directory, it should be relative. If it's between + # top level directories, leave it absolute. + my @src_dirs=split(m:/+:,$src); + my @dest_dirs=split(m:/+:,$dest); + if (@src_dirs > 0 && $src_dirs[0] eq $dest_dirs[0]) { + # Figure out how much of a path $src and $dest + # share in common. + my $x; + for ($x=0; $x < @src_dirs && $src_dirs[$x] eq $dest_dirs[$x]; $x++) {} + # Build up the new src. + $src=""; + for (1..$#dest_dirs - $x) { + $src.="../"; + } + for ($x .. $#src_dirs) { + $src.=$src_dirs[$_]."/"; + } + if ($x > $#src_dirs && ! length $src) { + $src="."; # special case + } + $src=~s:/$::; + } + else { + # Make sure it's properly absolute. + $src="/$src"; + } + + if (-d "$tmp/$dest" && ! -l "$tmp/$dest") { + error("link destination $tmp/$dest is a directory"); + } + doit("rm", "-f", "$tmp/$dest"); + doit("ln","-sf", $src, "$tmp/$dest"); +} + +# _expand_path expands all path "." and ".." components, but doesn't +# resolve symbolic links. +sub _expand_path { + my $start = @_ ? shift : '.'; + my @pathname = split(m:/+:,$start); + + my $entry; + my @respath; + foreach $entry (@pathname) { + if ($entry eq '.' || $entry eq '') { + # Do nothing + } + elsif ($entry eq '..') { + if ($#respath == -1) { + # Do nothing + } + else { + pop @respath; + } + } + else { + push @respath, $entry; + } + } + + my $result; + foreach $entry (@respath) { + $result .= '/' . $entry; + } + if (! defined $result) { + $result="/"; # special case + } + return $result; +} + # Checks if make's jobserver is enabled via MAKEFLAGS, but # the FD used to communicate with it is actually not available. sub is_make_jobserver_unavailable { diff --git a/dh_link b/dh_link index 5691a60..45a480f 100755 --- a/dh_link +++ b/dh_link @@ -84,42 +84,6 @@ the F<foo.1> =cut -# This expand_path expands all path "." and ".." components, but doesn't -# resolve symbolic links. -sub expand_path { - my $start = @_ ? shift : '.'; - my @pathname = split(m:/+:,$start); - - my $entry; - my @respath; - foreach $entry (@pathname) { - if ($entry eq '.' || $entry eq '') { - # Do nothing - } - elsif ($entry eq '..') { - if ($#respath == -1) { - # Do nothing - } - else { - pop @respath; - } - } - else { - push @respath, $entry; - } - } - - my $result; - foreach $entry (@respath) { - $result .= '/' . $entry; - } - if (! defined $result) { - $result="/"; # special case - } - return $result; -} - - init(); foreach my $package (@{$dh{DOPACKAGES}}) { @@ -171,55 +135,8 @@ foreach my $package (@{$dh{DOPACKAGES}}) { while (@links) { my $dest=pop @links; - my $src=expand_path(pop @links); - - $src=~s:^/::; - $dest=~s:^/::; - - if ($src eq $dest) { - warning("skipping link from $src to self"); - next; - } - - # Make sure the directory the link will be in exists. - my $basedir=dirname("$tmp/$dest"); - if (! -e $basedir) { - doit("install","-d",$basedir); - } - - # Policy says that if the link is all within one toplevel - # directory, it should be relative. If it's between - # top level directories, leave it absolute. - my @src_dirs=split(m:/+:,$src); - my @dest_dirs=split(m:/+:,$dest); - if (@src_dirs > 0 && $src_dirs[0] eq $dest_dirs[0]) { - # Figure out how much of a path $src and $dest - # share in common. - my $x; - for ($x=0; $x < @src_dirs && $src_dirs[$x] eq $dest_dirs[$x]; $x++) {} - # Build up the new src. - $src=""; - for (1..$#dest_dirs - $x) { - $src.="../"; - } - for ($x .. $#src_dirs) { - $src.=$src_dirs[$_]."/"; - } - if ($x > $#src_dirs && ! length $src) { - $src.="."; # special case - } - $src=~s:/$::; - } - else { - # Make sure it's properly absolute. - $src="/$src"; - } - - if (-d "$tmp/$dest" && ! -l "$tmp/$dest") { - error("link destination $tmp/$dest is a directory"); - } - doit("rm", "-f", "$tmp/$dest"); - doit("ln","-sf", $src, "$tmp/$dest"); + my $src=pop @links; + make_symlink($dest, $src, $tmp); } } diff --git a/doc/PROGRAMMING b/doc/PROGRAMMING index b6d3d16..a861422 100644 --- a/doc/PROGRAMMING +++ b/doc/PROGRAMMING @@ -250,6 +250,10 @@ load_log($package, $hashref) write_log($cmd, $package ...) Writes the log files for the specified package(s), adding the cmd to the end. +make_symlink($src, $dest, $tmp) + Creates a Policy compliant sytem link called $dest pointing to + $src. If $tmp is given, then $tmp will be prefixed to $dest when + creating the actual symlink. Sequence Addons: --------------- -- 1.7.2.3