]> arthur.barton.de Git - netatalk.git/commitdiff
added contrib/shell_utils/cleanappledouble.pl script from Heath Kehoe <hakehoe@avalon...
authorrufustfirefly <rufustfirefly>
Mon, 2 Apr 2001 19:12:12 +0000 (19:12 +0000)
committerrufustfirefly <rufustfirefly>
Mon, 2 Apr 2001 19:12:12 +0000 (19:12 +0000)
ChangeLog
contrib/shell_utils/Makefile.am
contrib/shell_utils/cleanappledouble.pl [new file with mode: 0755]

index d4f28799aab7843b1f65c7f74cc2e80e7af81f47..6c9c0c6d595758bdfc6acfb52658be16bd8e21f6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+
+2001-04-02  jeff b  <jeff@univrel.pr.uconn.edu>  
+
+       * contrib/shell_utils/Makefile.am, contrib/shell_utils/cleanappledouble.pl:
+       added cleanappledouble.pl script from Heath Kehoe <hakehoe@avalon.net>
+
+2001-03-26  jeff b  <jeff@univrel.pr.uconn.edu>  
+
+       * etc/afpd/quota.c: fix compile dbtob problem on Linux from Sam
+       Noble <ns@shadow.org>
+
+       * configure.in, etc/uams/Makefile.am, etc/uams/uams_krb4/Makefile.am:
+       moved -shared into LDSHAREDFLAGS to fix Solaris build problems
+       from Bob Rogers <rogers-netatalk-devel@rgrjr.dyndns.org> and
+       Akop Pogosian <akopps@csua.berkeley.edu>
+
 2001-03-22  Lance Levsen  <lance.l@dontspam.home.com>
 
        * etc/uams/Makefile.am: Added $LDFLAGS to fix broken compile due
index 66235cbcd310d0aef9f5ca2dde56cbeda9d4351b..c88e7312cb1dac861c4e03fb364c3629caead4d5 100644 (file)
@@ -10,6 +10,6 @@ SUFFIXES = .tmpl .
 
 CLEANFILES = lp2pap.sh
 
-bin_SCRIPTS = apple_cp apple_mv apple_rm lp2pap.sh
+bin_SCRIPTS = apple_cp apple_mv apple_rm cleanappledouble.pl lp2pap.sh
 
 EXTRA_DIST = $(bin_SCRIPTS)
diff --git a/contrib/shell_utils/cleanappledouble.pl b/contrib/shell_utils/cleanappledouble.pl
new file mode 100755 (executable)
index 0000000..2811e58
--- /dev/null
@@ -0,0 +1,167 @@
+#! /usr/bin/perl
+#
+# cleanappledouble.pl
+# Copyright (C) 2001 Heath Kehoe <hakehoe@avalon.net>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+
+require 5;
+use Getopt::Std;
+
+sub usage {
+    print STDERR <<EOF;
+Usage: $0 [-r] [-v] directory [directory ...]
+
+Scans each directory and:
+ 1) removes orphaned .AppleDouble files (from <directory>/.AppleDouble)
+ 2) fixes permissions on .AppleDouble files to match corresponding data file (minus x bits)
+ 3) fixes owner/group of .AppleDouble files to match corresponding data file (root only)
+
+Options:
+  -r   Recursively check all subdirectories of each directory
+  -R   Like -r but follows symbolic links to directories (warning: no loop-checking is done)
+  -p   Preview: no deletions or changes are actually made
+  -v   Verbose
+EOF
+    exit 1;
+}
+
+$isroot = ($> == 0);
+
+sub S_ISDIR {
+    my($mode) = @_;
+    return (($mode & 0170000) == 0040000);
+}
+sub S_ISREG {
+    my($mode) = @_;
+    return (($mode & 0170000) == 0100000);
+}
+sub S_ISLNK {
+    my($mode) = @_;
+    return (($mode & 0170000) == 0120000);
+}
+
+
+sub do_dir {
+    my($dir) = @_;
+    my($f, $havead, @dirlist, $mode, $uid, $gid, $fn);
+    my(%dm, %du, %dg);
+
+    print STDERR "Scanning $dir ...\n" if($opt_v);
+
+    $havead = -d "$dir/.AppleDouble";
+
+    # there's nothing more to do if we're not recursive and there's no .AppleDouble
+    return if(!$havead && !$opt_r);
+
+    opendir DIR, $dir  or do {
+               warn "Can't opendir $dir: $!\n";
+               return;
+    };
+    while(defined($f = readdir DIR)) {
+       next if($f eq ".");
+       next if($f eq "..");
+       next if($f eq ".AppleDouble");
+       next if($f eq ".AppleDesktop");
+
+       (undef, undef, $mode, undef, $uid, $gid) = lstat "$dir/$f";
+       next if(!defined($mode));
+
+       if(S_ISLNK($mode)) {
+           (undef, undef, $mode, undef, $uid, $gid) = stat "$dir/$f";
+           next if(!defined($mode));
+           next if(S_ISDIR($mode) && !$opt_R);
+       } 
+       if(S_ISDIR($mode)) {
+           push @dirlist, $f if($opt_r);
+       } elsif(S_ISREG($mode)) {
+           if($havead) {
+               $dm{$f} = $mode & 0666;
+               $du{$f} = $uid;
+               $dg{$f} = $gid;
+           }
+       } else {
+           warn "Ignoring special file: $dir/$f\n";
+       }
+    }
+    closedir DIR;
+
+    if($havead) {
+       if(opendir DIR, "$dir/.AppleDouble") {
+           while(defined($f = readdir DIR)) {
+               next if($f eq ".");
+               next if($f eq "..");
+               next if($f eq ".Parent");
+
+               $fn = "$dir/.AppleDouble/$f";
+               (undef, undef, $mode, undef, $uid, $gid) = stat $fn;
+               next if(!defined($mode));
+
+               if(S_ISDIR($mode)) {
+                   warn "Found subdirectory $f in $dir/.AppleDouble\n";
+                   next;
+               }
+               unless(exists $dm{$f}) {
+                   print STDERR "Deleting $fn ...\n" if($opt_v);
+                   if($opt_p) {
+                       print "rm '$fn'\n";
+                   } else {
+                       unlink "$fn" or warn "Can't unlink $fn: $!\n";
+                   }
+                   next;
+               }
+               $mode = $mode & 07777;
+               if($mode != $dm{$f}) {
+                   printf STDERR "Changing permissions from %o to %o on $fn\n", $mode, $dm{$f} if($opt_v);
+                   if($opt_p) {
+                       printf "chmod %o '$fn'\n", $dm{$f};
+                   } else {
+                       chmod $dm{$f}, $fn or warn "Can't chmod $fn: $!\n";
+                   }
+               }
+               if($isroot && ($uid != $du{$f} || $gid != $dg{$f})) {
+                   print STDERR "Changing owner from $uid:$gid to $du{$f}:$dg{$f} on $fn\n" if($opt_v);
+                   if($opt_p) {
+                       print "chown $du{$f}:$dg{$f} '$fn'\n";
+                   } else {
+                       chown $du{$f}, $dg{$f}, $fn or warn "Can't chown $fn: $!\n";
+                   }
+               }
+           }
+           closedir DIR;
+       } else {
+           warn "Can't opendir $dir/.AppleDouble: $!\n";
+       }
+    }
+
+    if($opt_r) {
+       foreach $f ( @dirlist ) {
+           do_dir("$dir/$f");
+       }
+    }
+}
+
+usage unless(getopts 'prRv');
+usage if(@ARGV == 0);
+
+if($opt_R) {
+    $opt_r = 1;
+}
+
+foreach $d ( @ARGV ) {
+    do_dir $d;
+}
+