New version of make_junction.pl
authordario
Thu, 14 May 2009 15:22:51 +0100
changeset 81 8eef886f83b9
parent 80 1b428f25477e
child 82 51cb6051c75d
New version of make_junction.pl
common/smoketest/make_junction.pl
--- a/common/smoketest/make_junction.pl	Wed May 13 13:59:56 2009 +0100
+++ b/common/smoketest/make_junction.pl	Thu May 14 15:22:51 2009 +0100
@@ -2,6 +2,7 @@
 
 use strict;
 use Getopt::Long;
+use File::Spec;
 
 my $link;
 my $target;
@@ -34,6 +35,25 @@
 die("Need command \"junction\". Not found\n"), if ($junction_help =~ /is not recognised/);
 die("Directory \"$target\" not found\n"), unless -d "$target";
 
+my ($vol,$dir,$file) = File::Spec->splitpath($target);
+my @subst_lines = `subst`;
+
+foreach (@subst_lines) {
+    my $line = $_;
+    chomp($line);
+    $line =~ /^(.:)\\: => (.*)$/;
+    die("Cannot parse output of 'subst'. Bailing out confused."), unless (defined($1) and defined($2));    
+    my $subst_drive = $1;
+    my $subst_targ = $2;
+    if (lc($subst_drive) eq lc($vol)) {
+        print("Target $target is in a substituted drive: $line\n");
+        $target = File::Spec->catfile(($subst_targ,$dir),$file);
+        print("Target $target will be used\n");
+        last;
+    }
+}
+
+
 if ( -e "$link") {
     print("\"$link\" already exists. ");
     if (!$force) {
@@ -78,7 +98,8 @@
             "options:\n" .
             "  --help                        Display this help and exit\n" .
             "  --link=LINKDIR                LINKDIR specifies the junction to be created. Last component is the junction. The rest must exist\n" .
-            "  --target=TARGDIR              TARGDIR is directory to which the junction will point.\n";
+            "  --target=TARGDIR              TARGDIR is directory to which the junction will point.\n" .
+            "                                If TARGDIR is in a substed drive, the real path will be used.\n";
     exit $error;            
 }