[debhelper-devel] [debhelper] 10/10: Added make_symlink to create Policy compliant symlinks
Niels Thykier
nthykier at moszumanska.debian.org
Thu Jan 1 17:12:02 UTC 2015
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository debhelper.
commit 0972742d81d108110c40943648f1f6b334b12d19
Author: Niels Thykier <niels at thykier.net>
Date: Sat Jan 15 21:38:27 2011 +0100
Added make_symlink to create Policy compliant symlinks
Signed-off-by: Niels Thykier <niels at thykier.net>
---
Debian/Debhelper/Dh_Lib.pm | 93 +++++++++++++++++++++++++++++++++++++++++++++-
debian/changelog | 3 ++
dh_link | 87 +------------------------------------------
doc/PROGRAMMING | 4 ++
4 files changed, 101 insertions(+), 86 deletions(-)
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 0519d20..55d150d 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -17,7 +17,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 &commit_override_log
- &dpkg_architecture_value &sourcepackage
+ &dpkg_architecture_value &sourcepackage &make_symlink
&is_make_jobserver_unavailable &clean_jobserver_makeflags
&cross_command &set_buildflags &get_buildoption);
@@ -936,6 +936,97 @@ 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;
+ $tmp = '' if not defined($tmp);
+ $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 @respath;
+ for my $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;
+ for my $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/debian/changelog b/debian/changelog
index a10537c..5077825 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -18,6 +18,9 @@ debhelper (9.20150101.1) UNRELEASED; urgency=medium
* dh_icons: Apply patch from Jérémy Bobbio to ensure stable
ordering of the icon list inserted into generated maintainer
scripts. (Closes: #774102)
+ * Dh_lib: Add a public "make_symlink" subroutine allowing
+ dh_*-like tools to generate policy compliant symlinks without
+ invoking dh_link. (Closes: #610173)
-- Niels Thykier <niels at thykier.net> Thu, 01 Jan 2015 17:24:38 +0100
diff --git a/dh_link b/dh_link
index db4aea8..7b49b36 100755
--- a/dh_link
+++ b/dh_link
@@ -86,42 +86,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}}) {
@@ -173,55 +137,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 e7b6e35..8723e4f 100644
--- a/doc/PROGRAMMING
+++ b/doc/PROGRAMMING
@@ -263,6 +263,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:
---------------
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git
More information about the debhelper-devel
mailing list