[Rt-commit] rt branch, 4.0/ignore-symlinks-for-relocatable-test-dirs, created. rt-4.0.8-153-g99f63d4

Thomas Sibley trs at bestpractical.com
Thu Nov 8 18:44:44 EST 2012


The branch, 4.0/ignore-symlinks-for-relocatable-test-dirs has been created
        at  99f63d47afc7608717eac42a76a9c02ae6162aa9 (commit)

- Log -----------------------------------------------------------------
commit 99f63d47afc7608717eac42a76a9c02ae6162aa9
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Nov 8 15:42:36 2012 -0800

    Ignore symlinks in the testing tree when using get_relocatable_dir/file()
    
    Parent directory traversals (C<..> or File::Spec->updir()) are naively
    canonicalized based on the test file path (C<$0>) so that symlinks
    aren't followed.  This is the exact opposite behaviour of most
    filesystems and is considered "wrong", however it is necessary for some
    subsets of tests which are symlinked into the testing tree.

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 36f0f87..b2828ea 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1079,17 +1079,28 @@ sub clean_caught_mails {
 Takes a path relative to the location of the test file that is being
 run and returns a path that takes the invocation path into account.
 
-e.g. RT::Test::get_relocatable_dir(File::Spec->updir(), 'data', 'emails')
+e.g. C<RT::Test::get_relocatable_dir(File::Spec->updir(), 'data', 'emails')>
+
+Parent directory traversals (C<..> or File::Spec->updir()) are naively
+canonicalized based on the test file path (C<$0>) so that symlinks aren't
+followed.  This is the exact opposite behaviour of most filesystems and is
+considered "wrong", however it is necessary for some subsets of tests which are
+symlinked into the testing tree.
 
 =cut
 
 sub get_relocatable_dir {
-    (my $volume, my $directories, my $file) = File::Spec->splitpath($0);
-    if (File::Spec->file_name_is_absolute($directories)) {
-        return File::Spec->catdir($directories, @_);
-    } else {
-        return File::Spec->catdir(File::Spec->curdir(), $directories, @_);
+    my @directories = File::Spec->splitdir(
+        File::Spec->rel2abs((File::Spec->splitpath($0))[1])
+    );
+    push @directories, File::Spec->splitdir($_) for @_;
+
+    my @clean;
+    for (@directories) {
+        if    ($_ eq "..") { pop @clean      }
+        elsif ($_ ne ".")  { push @clean, $_ }
     }
+    return File::Spec->catdir(@clean);
 }
 
 =head2 get_relocatable_file

-----------------------------------------------------------------------


More information about the Rt-commit mailing list