equal
deleted
inserted
replaced
1 #!/usr/bin/perl |
1 #!/usr/bin/perl |
2 |
2 |
3 use strict; |
3 use strict; |
4 use Getopt::Long; |
4 use Getopt::Long; |
|
5 use File::Spec; |
5 |
6 |
6 my $link; |
7 my $link; |
7 my $target; |
8 my $target; |
8 my $help; |
9 my $help; |
9 my $force = 0; |
10 my $force = 0; |
31 usage_error(), unless (defined($link) && defined($target)); |
32 usage_error(), unless (defined($link) && defined($target)); |
32 |
33 |
33 my $junction_help = `junction /?`; |
34 my $junction_help = `junction /?`; |
34 die("Need command \"junction\". Not found\n"), if ($junction_help =~ /is not recognised/); |
35 die("Need command \"junction\". Not found\n"), if ($junction_help =~ /is not recognised/); |
35 die("Directory \"$target\" not found\n"), unless -d "$target"; |
36 die("Directory \"$target\" not found\n"), unless -d "$target"; |
|
37 |
|
38 my ($vol,$dir,$file) = File::Spec->splitpath($target); |
|
39 my @subst_lines = `subst`; |
|
40 |
|
41 foreach (@subst_lines) { |
|
42 my $line = $_; |
|
43 chomp($line); |
|
44 $line =~ /^(.:)\\: => (.*)$/; |
|
45 die("Cannot parse output of 'subst'. Bailing out confused."), unless (defined($1) and defined($2)); |
|
46 my $subst_drive = $1; |
|
47 my $subst_targ = $2; |
|
48 if (lc($subst_drive) eq lc($vol)) { |
|
49 print("Target $target is in a substituted drive: $line\n"); |
|
50 $target = File::Spec->catfile(($subst_targ,$dir),$file); |
|
51 print("Target $target will be used\n"); |
|
52 last; |
|
53 } |
|
54 } |
|
55 |
36 |
56 |
37 if ( -e "$link") { |
57 if ( -e "$link") { |
38 print("\"$link\" already exists. "); |
58 print("\"$link\" already exists. "); |
39 if (!$force) { |
59 if (!$force) { |
40 my $choice; |
60 my $choice; |
76 " make_junction.pl --help\n" . |
96 " make_junction.pl --help\n" . |
77 " make_junction.pl --link=LINKDIR --target=TARGDIR\n " . |
97 " make_junction.pl --link=LINKDIR --target=TARGDIR\n " . |
78 "options:\n" . |
98 "options:\n" . |
79 " --help Display this help and exit\n" . |
99 " --help Display this help and exit\n" . |
80 " --link=LINKDIR LINKDIR specifies the junction to be created. Last component is the junction. The rest must exist\n" . |
100 " --link=LINKDIR LINKDIR specifies the junction to be created. Last component is the junction. The rest must exist\n" . |
81 " --target=TARGDIR TARGDIR is directory to which the junction will point.\n"; |
101 " --target=TARGDIR TARGDIR is directory to which the junction will point.\n" . |
|
102 " If TARGDIR is in a substed drive, the real path will be used.\n"; |
82 exit $error; |
103 exit $error; |
83 } |
104 } |
84 |
105 |
85 sub help() |
106 sub help() |
86 { |
107 { |