3 ###############################################################################
6 # Author : Chris Koeritz #
7 # Rights : Copyright (C) 1996-$now by Author #
11 # Processes arguments that are expected to be directories. The directory #
12 # has all the known junk files strained out of it and then it is removed #
15 ###############################################################################
16 # This program is free software; you can redistribute it and/or modify it #
17 # under the terms of the GNU General Public License as published by the Free #
18 # Software Foundation; either version 2 of the License or (at your option) #
19 # any later version. See: "http://www.gruntose.com/Info/GNU/GPL.html" for a #
20 # version of the License. Please send any updates to "fred@gruntose.com". #
21 ###############################################################################
23 require "filename_helper.pl";
25 ############################################################################
27 sub remove_whackables {
28 local($from_dir) = @_;
30 # open the directory and grab all the files out.
31 opendir CHECK, $from_dir;
32 local(@files) = readdir(CHECK);
35 # iterate over the potentially whackable files.
37 foreach $fname (@files) {
38 #print "filename is $fname\n";
39 # check if this one matches one of our patterns.
40 if (! &important_filename($fname)) {
41 # it's a junk file; whack it.
42 $fname = $from_dir . '/' . $fname;
43 #print "whacking: $fname.\n";
46 print "cleaning file: $fname\n";
47 &recursive_delete($fname);
49 print "skipping item rather than deleting: $fname\n";
55 ############################################################################
58 local(@zap_list) = @_;
60 foreach $to_zap (@zap_list) {
63 #print "to_zap is $to_zap\n";
65 print "$to_zap is not a directory.\n";
69 if ($to_zap =~ /^.*\.svn.*$/) {
70 #print "hey found a .svn dir! skipping.\n";
74 &remove_whackables($to_zap);
75 opendir WHACK, $to_zap;
76 @files_left = readdir(WHACK);
80 local($seen_anything) = "";
81 foreach $name (@files_left) {
82 # check if directory has nothing but the two directory entries in it.
83 if ( ($name ne ".") && ($name ne "..") ) {
84 if ($to_zap =~ /^.*\.svn.*$/) {
85 print "not empty: \"$to_zap/$name\"\n";
87 $seen_anything = "true";
92 if (length($seen_anything)) {
93 print "not empty: \"$to_zap\"\n";
95 # this should now work, if the directory is empty.
97 print "still in use: \"$to_zap\"\n";
104 ############################################################################
106 sub recursively_zap_dirs {
107 local(@zap_dirs) = @_;
108 local($zap_dir) = "";
109 foreach $zap_dir (@zap_dirs) {
110 #hmmm: can we use a perl utility to do the directory recursion?
111 local(@dirnames) = `find \"$zap_dir\" -depth -mindepth 1 -type d`;
112 #print "dirnames are:\n@dirnames\n";
113 &zap_the_dir(@dirnames);
114 &zap_the_dir($zap_dir);
118 ############################################################################