1#! /usr/bin/perl -w 2 3# Copyright (C) 1995, 1996, 1997, 2007, 2008, 2009 Free Software 4# Foundation, Inc. 5 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <http://www.gnu.org/licenses/>. 18 19 20# This script is a very lame hack to remove local files, until the 21# time when Wget proper will have this functionality. 22# Use with utmost care! 23 24# If the remote server supports BSD-style listings, set this to 0. 25$sysvlisting = 1; 26 27$verbose = 0; 28 29if (@ARGV && ($ARGV[0] eq '-v')) { 30 shift; 31 $verbose = 1; 32} 33 34(@dirs = @ARGV) || push (@dirs,'.'); 35 36 37foreach $_ (@dirs) { 38 &procdir($_); 39} 40 41# End here 42 43sub procdir 44{ 45 local $dir = shift; 46 local(@lcfiles, @lcdirs, %files, @fl); 47 48 print STDERR "Processing directory '$dir':\n" if $verbose; 49 50 opendir(DH, $dir) || die("Cannot open $dir: $!\n"); 51 @lcfiles = (); 52 @lcdirs = (); 53 # Read local files and directories. 54 foreach $_ (readdir(DH)) { 55 /^(\.listing|\.\.?)$/ && next; 56 lstat ("$dir/$_"); 57 if (-d _) { 58 push (@lcdirs, $_); 59 } 60 else { 61 push (@lcfiles, $_); 62 } 63 } 64 closedir(DH); 65 # Parse .listing 66 if (open(FD, "<$dir/.listing")) { 67 while (<FD>) 68 { 69 # Weed out the line beginning with 'total' 70 /^total/ && next; 71 # Weed out everything but plain files and symlinks. 72 /^[-l]/ || next; 73 @fl = split; 74 $files{$fl[7 + $sysvlisting]} = 1; 75 } 76 close FD; 77 foreach $_ (@lcfiles) { 78 if (!$files{$_}) { 79 print "$dir/$_\n"; 80 } 81 } 82 } 83 else { 84 print STDERR "Warning: $dir/.listing: $!\n"; 85 } 86 foreach $_ (@lcdirs) { 87 &procdir("$dir/$_"); 88 } 89} 90 91