3 # This file is part of GNU Stow.
5 # GNU Stow is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # GNU Stow is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see https://www.gnu.org/licenses/.
26 my $DEFAULT_TARGET = $ENV{STOW_DIR} || '/usr/local/';
28 our $Wanted = \&bad_links;
31 our $Target = $DEFAULT_TARGET;
33 # put the main loop into a block so that tests can load this as a module
39 #check_stow($Target, $Wanted);
45 'b|badlinks' => sub { $Wanted = \&bad_links },
46 'a|aliens' => sub { $Wanted = \&aliens },
47 'l|list' => sub { $Wanted = \&list },
48 't|target=s' => \$Target,
55 USAGE: chkstow [options]
58 -t DIR, --target=DIR Set the target directory to DIR
59 (default is $DEFAULT_TARGET)
60 -b, --badlinks Report symlinks that point to non-existent files
61 -a, --aliens Report non-symlinks in the target directory
62 -l, --list List packages in the target directory
64 --badlinks is the default mode.
70 #my ($Target, $Wanted) = @_;
74 preprocess => \&skip_dirs,
77 find(\%options, $Target);
79 if ($Wanted == \&list) {
81 delete $Package{'..'};
84 print map "$_\n", sort(keys %Package);
91 # skip stow source and unstowed targets
92 if (-e ".stow" || -e ".notstowed" ) {
93 warn "skipping $File::Find::dir\n";
101 # checking for files that do not link to anything
103 -l && !-e && print "Bogus link: $File::Find::name\n";
106 # checking for files that are not owned by stow
108 !-l && !-d && print "Unstowed file: $File::Find::name\n";
111 # just list the packages in the target directory
112 # FIXME: what if the stow dir is not called 'stow'?
116 s{\A(?:\.\./)+stow/}{}g;
122 1; # Hey, it's a module!