[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, lab-refactor, updated. 2.5.3-95-g881101b



The following commit has been merged in the lab-refactor branch:
commit 881101b82ae7ee0e3bb5de481c6d3b0c33106f81
Author: Niels Thykier <niels@thykier.net>
Date:   Sun Oct 2 19:14:43 2011 +0200

    Lintian::Lab: Defer path resolution until create_lab if needed
    
    It is not possible to resolve a path if it does not exists.  The
    Lintian::Lab constructor will no longer croak if path resolution
    fails.  Instead it will be re-tried at create_lab time if needed.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/lib/Lintian/Lab.pm b/lib/Lintian/Lab.pm
index dd291d2..f7b1bf6 100644
--- a/lib/Lintian/Lab.pm
+++ b/lib/Lintian/Lab.pm
@@ -115,10 +115,18 @@ sub new {
     my ($class, $dir) = @_;
     my $absdir;
     my $mode = LAB_MODE_TEMP;
+    my $dok = 1;
     if ($dir) {
-        $absdir = Cwd::abs_path ($dir);
-        croak "Cannot resolve $dir: $!" unless $absdir;
         $mode = LAB_MODE_STATIC;
+        $absdir = Cwd::abs_path ($dir);
+        if (!$absdir) {
+            if ($dir =~ m,^/,o) {
+                $absdir = $dir;
+            } else {
+                $absdir = Cwd::cwd . '/' . $dir;
+            }
+            $dok = 0;
+        }
     } else {
         $absdir = ''; #Ensure it is defined.
     }
@@ -132,6 +140,7 @@ sub new {
         'is_open'     => 0,
         'keep-lab'    => 0,
     };
+    $self->{'_correct_dir'} = 1 unless $dok;
     bless $self, $class;
     $self->_init ($dir);
     return $self;
@@ -359,20 +368,22 @@ sub generate_diffs {
 
 =item $lab->create_lab ([$opts])
 
-Creates a new lab.  It will create $self->dir if it does not
-exists.  It will also create a basic lab empty lab.  If this is
-a temporary lab, this method will also setup the temporary dir
-for the lab.
+Creates a new lab.  It will create $lab->dir if it does not exists.
+It will also create a basic lab empty lab.  If this is a temporary
+lab, this method will also setup the temporary dir for the lab.
 
 B<$opts> (if present) is a hashref containing options.  Currently only
 "keep-lab" is recognized.  If "keep-lab" points to a truth value the
 temporary directory will I<not> be removed by closing the lab (nor
 exiting the application).  However, explicitly calling
-$self->remove_lab will remove the lab.
+$lab->remove_lab will remove the lab.
 
-Note: This will not create parent directories of $self->dir and will
+Note: This will not create parent directories of $lab->dir and will
 croak if these does not exists.
 
+Note: This may update the value of $lab->dir as resolving the path
+requires it to exists.
+
 =cut
 
 sub create_lab {
@@ -400,6 +411,17 @@ sub create_lab {
     # absolute.
     croak "Cannot create $dir: $!" unless -d $dir or mkdir $dir;
 
+    if ($self->{'_correct_dir'}) {
+        # This happens if $dir has been created in this call.
+        # Until now we have been unable to fully resolve the path,
+        # so we try now.
+        my $absdir = Cwd::abs_path ($dir);
+        croak "Cannot resolve $dir: $!" unless $absdir;
+        delete $self->{'_correct_dir'};
+        $dir = $absdir;
+        $self->{'dir'} = $absdir;
+    }
+
     # Top dir exists, time to create the minimal directories.
     unless (-d "$dir/info") {
         mkdir "$dir/info" or croak "mkdir $dir/info: $!";

-- 
Debian package checker


Reply to: