2010-06-04 05:12:19 -04:00
|
|
|
#!/usr/bin/env perl -w
|
1999-12-02 02:42:23 -05:00
|
|
|
|
2011-01-01 07:19:37 -05:00
|
|
|
# Copyright (C) 1995, 1996, 1997, 2007, 2008, 2009, 2010, 2011 Free
|
|
|
|
# Software Foundation, Inc.
|
1999-12-02 02:42:23 -05:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-07-10 01:53:22 -04:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
1999-12-02 02:42:23 -05:00
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2007-07-10 01:53:22 -04:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1999-12-02 02:42:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
# This script is a very lame hack to remove local files, until the
|
|
|
|
# time when Wget proper will have this functionality.
|
|
|
|
# Use with utmost care!
|
|
|
|
|
|
|
|
# If the remote server supports BSD-style listings, set this to 0.
|
|
|
|
$sysvlisting = 1;
|
|
|
|
|
|
|
|
$verbose = 0;
|
|
|
|
|
|
|
|
if (@ARGV && ($ARGV[0] eq '-v')) {
|
|
|
|
shift;
|
|
|
|
$verbose = 1;
|
|
|
|
}
|
|
|
|
|
2000-11-01 19:21:53 -05:00
|
|
|
(@dirs = @ARGV) || push (@dirs,'.');
|
|
|
|
|
1999-12-02 02:42:23 -05:00
|
|
|
|
|
|
|
foreach $_ (@dirs) {
|
|
|
|
&procdir($_);
|
|
|
|
}
|
|
|
|
|
|
|
|
# End here
|
|
|
|
|
|
|
|
sub procdir
|
|
|
|
{
|
2000-11-01 19:21:53 -05:00
|
|
|
local $dir = shift;
|
1999-12-02 02:42:23 -05:00
|
|
|
local(@lcfiles, @lcdirs, %files, @fl);
|
|
|
|
|
|
|
|
print STDERR "Processing directory '$dir':\n" if $verbose;
|
2009-01-23 16:09:48 -05:00
|
|
|
|
1999-12-02 02:42:23 -05:00
|
|
|
opendir(DH, $dir) || die("Cannot open $dir: $!\n");
|
|
|
|
@lcfiles = ();
|
|
|
|
@lcdirs = ();
|
|
|
|
# Read local files and directories.
|
|
|
|
foreach $_ (readdir(DH)) {
|
|
|
|
/^(\.listing|\.\.?)$/ && next;
|
2000-11-01 19:21:53 -05:00
|
|
|
lstat ("$dir/$_");
|
|
|
|
if (-d _) {
|
|
|
|
push (@lcdirs, $_);
|
1999-12-02 02:42:23 -05:00
|
|
|
}
|
|
|
|
else {
|
2000-11-01 19:21:53 -05:00
|
|
|
push (@lcfiles, $_);
|
1999-12-02 02:42:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(DH);
|
|
|
|
# Parse .listing
|
|
|
|
if (open(FD, "<$dir/.listing")) {
|
|
|
|
while (<FD>)
|
|
|
|
{
|
|
|
|
# Weed out the line beginning with 'total'
|
|
|
|
/^total/ && next;
|
|
|
|
# Weed out everything but plain files and symlinks.
|
|
|
|
/^[-l]/ || next;
|
|
|
|
@fl = split;
|
|
|
|
$files{$fl[7 + $sysvlisting]} = 1;
|
|
|
|
}
|
|
|
|
close FD;
|
|
|
|
foreach $_ (@lcfiles) {
|
|
|
|
if (!$files{$_}) {
|
|
|
|
print "$dir/$_\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print STDERR "Warning: $dir/.listing: $!\n";
|
|
|
|
}
|
|
|
|
foreach $_ (@lcdirs) {
|
|
|
|
&procdir("$dir/$_");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|