-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathassert-no-symlinks
executable file
·66 lines (52 loc) · 1.33 KB
/
assert-no-symlinks
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
63
64
65
66
#!/usr/bin/perl -w
# Fri Aug 26 16:34:34 EDT 2011
(my $email='XXX%YYY,ch')=~ tr/%,/@./;
use strict;
$0=~ /(.*?)([^\/]+)\z/s or die "?";
my ($mydir, $myname)=($1,$2);
sub usage {
print STDERR map{"$_\n"} @_ if @_;
print "$myname path(s)
Asserts that in every given path, every path segment is not a
symlink.
Given foo/bar/baz and /boo/x, it will only return true if none of
these paths is a symlink:
foo/bar/baz
foo/bar
foo
/boo/x
/boo
('/' and '.' aren't checked since they can't be a symlink.)
Dies pointing out the offending path; also dies if any of the paths
doesn't exist.
GRR I've already had check_paths_for_symlinks in this repo.
(Also, there's Chj::Path::Expand now which could accept certain symlinks)
(Christian Jaeger <$email>)
";
exit (@_ ? 1 : 0);
}
use Getopt::Long;
our $verbose=0;
#our $opt_dry;
GetOptions("verbose"=> \$verbose,
"help"=> sub{usage},
#"dry-run"=> \$opt_dry,
) or exit 1;
usage unless @ARGV;
use Chj::xperlfunc 'dirname','xlstat';
sub checkpath {
my ($path)=@_;
if ($path eq "/" or $path eq "" or $path eq ".") {
#end
} else {
my $s= xlstat $path;
if ($s->is_symlink) {
die "$myname: symlink at '$path'\n";
} else {
checkpath (dirname $path)
}
}
}
checkpath $_ for @ARGV;
#use Chj::ruse;
#use Chj::Backtrace; use Chj::repl; repl;