chiark / gitweb /
dgit: import-dsc: Handle relative symlinks correctly
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 13 Jan 2019 18:35:53 +0000 (18:35 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 1 Mar 2019 17:43:47 +0000 (17:43 +0000)
The logic here was correct only with bpd = `..'.

Closes: #913259
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
squash!! dgit: import-dsc: Handle relative symlinks correctly

dgit
tests/tests/import-dsc

diff --git a/dgit b/dgit
index ce7fdaef69457531129c58c6e7be5a2da25d3cc1..3032c56d5f3f7a7178b41dd69e5a67e6a125905d 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -32,6 +32,7 @@ use Data::Dumper;
 use LWP::UserAgent;
 use Dpkg::Control::Hash;
 use File::Path;
+use File::Spec;
 use File::Temp qw(tempdir);
 use File::Basename;
 use Dpkg::Version;
@@ -7011,28 +7012,37 @@ END
        # or something.
        my $here = "$buildproductsdir/$f";
        if (lstat $here) {
-           next if stat $here;
+           if (stat $here) {
+               next;
+           }
            fail f_ "lstat %s works but stat gives %s !", $here, $!;
        }
        fail f_ "stat %s: %s", $here, $! unless $! == ENOENT;
        # $f does not exist in bpd, we need to transfer it
        my $there = $dscfn;
-       if ($dscfn =~ m#^(?:\./+)?\.\./+#) {
-           $there = $';
-       } elsif ($dscfn =~ m#^/#) {
-           $there = $dscfn;
+       $there =~ s{[^/]+$}{$f} or confess "$there ?";
+       # $there is file we want, relative to user's cwd, or abs
+       printdebug "not in bpd, $f, test $there ...\n";
+       stat $there or fail f_
+           "import %s requires %s, but: %s", $dscfn, $there, $!;
+       if ($there =~ m#^(?:\./+)?\.\./+#) {
+           # $there is relative to user's cwd
+           my $there_from_parent = $';
+           if ($buildproductsdir !~ m{^/}) {
+               # abs2rel, despite its name, can take two relative paths
+               $there = File::Spec->abs2rel($there,$buildproductsdir);
+               # now $there is relative to bpd, great
+           } else {
+               $there = (dirname $maindir)."/$there_from_parent";
+               # now $there is absoute
+           }
+       } elsif ($there =~ m#^/#) {
+           # $there is absolute already
        } else {
            fail f_
                "cannot import %s which seems to be inside working tree!",
                $dscfn;
        }
-       $there =~ s#/+[^/]+$## or fail f_
-           "import %s requires .../%s, but it does not exist",
-           $dscfn, $f;
-       $there .= "/$f";
-       my $test = $there =~ m{^/} ? $there : "../$there";
-       stat $test or fail f_
-           "import %s requires %s, but: %s", $dscfn, $test, $!;
        symlink $there, $here or fail f_
            "symlink %s to %s: %s", $there, $here, $!;
        progress f_ "made symlink %s -> %s", $here, $there;
index bdd849ca1060e75d8fcff9aac988d5ea94b7a4a0..4a8d876693af72c7bf548ee4ae2274e4dee5830a 100755 (executable)
@@ -79,7 +79,7 @@ dsc=$troot/pkg-srcs/${p}_${v}.dsc
 cd $p.2
 
 cp $dsc ..
-t-expect-fail 'it does not exist' \
+t-expect-fail 'No such file or directory' \
 check-import .. $v
 
 mkdir ../enoents