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";
24 require "importenv.pl";
26 ############################################################################
28 sub remove_whackables {
29 local($from_dir) = @_;
31 # open the directory and grab all the files out.
32 opendir CHECK, $from_dir;
33 local(@files) = readdir(CHECK);
36 # iterate over the potentially whackable files.
38 foreach $fname (@files) {
39 #print "filename is $fname\n";
40 # check if this one matches one of our patterns.
41 if (! &important_filename($fname)) {
42 # it's a junk file; whack it.
43 $fname = $from_dir . '/' . $fname;
44 #print "whacking: $fname.\n";
47 print "recursively deleting directory: $fname\n";
48 &recursive_delete($fname);
54 ############################################################################
57 local(@zap_list) = @_;
59 foreach $to_zap (@zap_list) {
62 #print "to_zap is $to_zap\n";
64 print "$to_zap is not a directory.\n";
68 if ($to_zap =~ /^.*\.svn.*$/) {
69 #print "hey found a .svn dir! skipping.\n";
73 &remove_whackables($to_zap);
74 opendir WHACK, $to_zap;
75 @files_left = readdir(WHACK);
79 local($seen_anything) = "";
80 foreach $name (@files_left) {
81 # check if directory has nothing but the two directory entries in it.
82 if ( ($name ne ".") && ($name ne "..") ) {
83 if ($to_zap =~ /^.*\.svn.*$/) {
84 print "not empty: \"$to_zap/$name\"\n";
86 $seen_anything = "true";
91 if (length($seen_anything)) {
92 print "not empty: \"$to_zap\"\n";
94 # this should now work, if the directory is empty.
96 print "still in use: \"$to_zap\"\n";
103 ############################################################################
105 sub recursively_zap_dirs {
106 local(@zap_dirs) = @_;
107 local($zap_dir) = "";
108 foreach $zap_dir (@zap_dirs) {
109 #hmmm: can we use a perl utility to do the directory recursion?
110 local(@dirnames) = `find \"$zap_dir\" -depth -mindepth 1 -type d`;
111 #print "dirnames are:\n@dirnames\n";
112 &zap_the_dir(@dirnames);
113 &zap_the_dir($zap_dir);
117 ############################################################################