3
# $Id: cleanappledouble.pl.in,v 1.1 2002/01/17 05:59:25 srittau Exp $
6
# Copyright (C) 2001 Heath Kehoe <hakehoe@avalon.net>
8
# This program is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU General Public License
10
# as published by the Free Software Foundation; either version 2
11
# of the License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
Usage: $0 [-r] [-v] directory [directory ...]
30
Scans each directory and:
31
1) removes orphaned .AppleDouble files (from <directory>/.AppleDouble)
32
2) fixes permissions on .AppleDouble files to match corresponding data file (minus x bits)
33
3) fixes owner/group of .AppleDouble files to match corresponding data file (root only)
36
-r Recursively check all subdirectories of each directory
37
-R Like -r but follows symbolic links to directories (warning: no loop-checking is done)
38
-p Preview: no deletions or changes are actually made
48
return (($mode & 0170000) == 0040000);
52
return (($mode & 0170000) == 0100000);
56
return (($mode & 0170000) == 0120000);
62
my($f, $havead, @dirlist, $mode, $uid, $gid, $fn);
65
print STDERR "Scanning $dir ...\n" if($opt_v);
67
$havead = -d "$dir/.AppleDouble";
69
# there's nothing more to do if we're not recursive and there's no .AppleDouble
70
return if(!$havead && !$opt_r);
72
opendir DIR, $dir or do {
73
warn "Can't opendir $dir: $!\n";
76
while(defined($f = readdir DIR)) {
79
next if($f eq ".AppleDouble");
80
next if($f eq ".AppleDesktop");
82
(undef, undef, $mode, undef, $uid, $gid) = lstat "$dir/$f";
83
next if(!defined($mode));
86
(undef, undef, $mode, undef, $uid, $gid) = stat "$dir/$f";
87
next if(!defined($mode));
88
next if(S_ISDIR($mode) && !$opt_R);
91
push @dirlist, $f if($opt_r);
92
} elsif(S_ISREG($mode)) {
94
$dm{$f} = $mode & 0666;
99
warn "Ignoring special file: $dir/$f\n";
105
if(opendir DIR, "$dir/.AppleDouble") {
106
while(defined($f = readdir DIR)) {
109
next if($f eq ".Parent");
111
$fn = "$dir/.AppleDouble/$f";
112
(undef, undef, $mode, undef, $uid, $gid) = stat $fn;
113
next if(!defined($mode));
116
warn "Found subdirectory $f in $dir/.AppleDouble\n";
119
unless(exists $dm{$f}) {
120
print STDERR "Deleting $fn ...\n" if($opt_v);
124
unlink "$fn" or warn "Can't unlink $fn: $!\n";
128
$mode = $mode & 07777;
129
if($mode != $dm{$f}) {
130
printf STDERR "Changing permissions from %o to %o on $fn\n", $mode, $dm{$f} if($opt_v);
132
printf "chmod %o '$fn'\n", $dm{$f};
134
chmod $dm{$f}, $fn or warn "Can't chmod $fn: $!\n";
137
if($isroot && ($uid != $du{$f} || $gid != $dg{$f})) {
138
print STDERR "Changing owner from $uid:$gid to $du{$f}:$dg{$f} on $fn\n" if($opt_v);
140
print "chown $du{$f}:$dg{$f} '$fn'\n";
142
chown $du{$f}, $dg{$f}, $fn or warn "Can't chown $fn: $!\n";
148
warn "Can't opendir $dir/.AppleDouble: $!\n";
153
foreach $f ( @dirlist ) {
159
usage unless(getopts 'prRv');
160
usage if(@ARGV == 0);
166
foreach $d ( @ARGV ) {