source: trunk/essentials/net-misc/wget/util/rmold.pl

Last change on this file was 3440, checked in by bird, 18 years ago

wget 1.10.2

File size: 2.3 KB
Line 
1#! /usr/bin/perl -w
2
3# Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
4
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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
Note: See TracBrowser for help on using the repository browser.