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 "recursively deleting directory: $fname\n";
47 &recursive_delete($fname);
53 ############################################################################
56 local(@zap_list) = @_;
58 foreach $to_zap (@zap_list) {
61 #print "to_zap is $to_zap\n";
63 print "$to_zap is not a directory.\n";
67 if ($to_zap =~ /^.*\.svn.*$/) {
68 #print "hey found a .svn dir! skipping.\n";
72 &remove_whackables($to_zap);
73 opendir WHACK, $to_zap;
74 @files_left = readdir(WHACK);
78 local($seen_anything) = "";
79 foreach $name (@files_left) {
80 # check if directory has nothing but the two directory entries in it.
81 if ( ($name ne ".") && ($name ne "..") ) {
82 if ($to_zap =~ /^.*\.svn.*$/) {
83 print "not empty: \"$to_zap/$name\"\n";
85 $seen_anything = "true";
90 if (length($seen_anything)) {
91 print "not empty: \"$to_zap\"\n";
93 # this should now work, if the directory is empty.
95 print "still in use: \"$to_zap\"\n";
102 ############################################################################
104 sub recursively_zap_dirs {
105 local(@zap_dirs) = @_;
106 local($zap_dir) = "";
107 foreach $zap_dir (@zap_dirs) {
108 #hmmm: can we use a perl utility to do the directory recursion?
109 local(@dirnames) = `find \"$zap_dir\" -depth -mindepth 1 -type d`;
110 #print "dirnames are:\n@dirnames\n";
111 &zap_the_dir(@dirnames);
112 &zap_the_dir($zap_dir);
116 ############################################################################