File: ngx-links

package info (click to toggle)
nginx 1.18.0-6.1%2Bdeb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 19,344 kB
  • sloc: ansic: 250,653; perl: 7,548; sh: 1,408; ruby: 879; python: 358; makefile: 338; awk: 36; cpp: 18
file content (62 lines) | stat: -rwxr-xr-x 1,299 bytes parent folder | download | duplicates (6)
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
61
62
#!/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 existing 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;