forked from openresty/openresty-devel-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ngx-links
executable file
·62 lines (45 loc) · 1.27 KB
/
ngx-links
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env perl
use strict;
use warnings;
use Cwd qw( cwd );
use Getopt::Std;
my %opts;
getopts('f', \%opts) or
die "Usage: $0 [-f]
Options:
-f Override exising symbolic links with force
";
my $root = shift || 'src';
my $force = $opts{f};
opendir my $dir, $root
or die "Can't open directory src/ for reading: $!\n";
my @links;
while (my $entry = readdir $dir) {
my ($base, $ext);
my $source = "$root/$entry";
if (-l $source || -d $source) {
warn "skipping $source\n";
next;
}
if ($entry =~ m{ ^ ngx_ (?: \w+ _ )+ (\w+) \. ([ch]|rl) $}x) {
($base, $ext) = ($1, $2);
} else {
next;
}
my $target = "$root/$base.$ext";
if (-e $target && ! -l $target) {
die "target $target already exists, and not a symlink, not overriding...Abort.\n";
} elsif (-l $target) {
#warn "it's a link";
if ( ! $force ) {
die "target $target already exists, not overriding...Abort.\n";
}
warn "overriding existing symlink $target\n";
}
#warn "creating $target --> $root/$entry\n";
system("ln -svf `pwd`/$source $target") == 0 or
die "Failed to create the symlink\n";;
push @links, $target;
}
print join("\n", @links), "\n";
close $dir;