]> arthur.barton.de Git - netatalk.git/blob - bin/afile/acleandir.rc
Path and portability fix for this script
[netatalk.git] / bin / afile / acleandir.rc
1 #! /usr/bin/rc
2 #
3 # acleandir  [-rvnid] dir 
4 #
5 # removes orphan AppleDouble files
6 #
7 # gerry.tomlinson@ncl.ac.uk 2/3/98
8 #
9 # note - don't follow symbolic links to directories in recursive option
10
11
12 fn emptydir {
13 ~ $1/* $1/'*'  && return 0
14 return 1
15 }
16
17 fn doit {
18 ~ $ropt 1  && for (i in $1/*) {
19     [  -d  $i -a ! '(' $testsym $i ')' ] && doit $i
20 }
21
22 AD=$1/.AppleDouble
23 ADT=$1/.AppleDesktop
24
25 [ -d $AD ]  || return
26
27 #
28 # first handle the .AppleDesktop dir
29 #
30 if (~ $aopt 1 && [ -d $ADT ] ) {
31         if (~ $iopt 1 ) {
32               echo -n remove $ADT '?' 
33                ~ `{line} [yY] && rm -r $ADT
34         } else { 
35             if (~ $nopt 1) {
36                 echo $ADT to be removed
37             } else rm -r $ADT
38        }           
39 }
40
41 #
42 # now look at the .AppleDouble dir
43 #
44 emptydir $AD  || for (i in $AD/*) {
45     if (~ $aopt 1 || ! afile $i  >/dev/null >[2=1] ) {
46         sizemess = ()
47         size = `{wc -c $i}
48         ! ~ $size(1) 589 && sizemess = 'size='^$size(1)
49         if (~ $iopt 1 ) {
50             size = `{wc -c $i}
51             echo -n remove '`'$i''''^$sizemess^' ? '
52             ~ `{line} [yY] && rm  $i
53         } else {
54         if (~ $nopt 1 ) {            
55              echo '`'$i''''^' to be removed '^$sizemess
56         } else rm  $i && ~ $vopt 1 && echo $i removed  
57         }  
58     }
59  }
60
61 if ( ~ $dopt 1  && emptydir $AD ) {
62     rm -f $AD/.Parent
63     rmdir $AD >/dev/null >[2=1]  && ~ $vopt 1 && echo empty directory $AD removed
64 }
65
66
67
68 }
69
70 #
71 # start here
72 #
73
74 #
75 # first cope with different test for symlink options
76 #
77 testsym = -L
78 [ - L . ] >[2] /dev/null 
79 ~ $status 1 || testsym = -h
80
81 ~$#* 0 || * =`{getopt darnviR $*}
82
83 for (i) {
84     switch ($i) {
85     case -[rR]
86             shift; ropt = 1
87     case -v
88             shift; vopt = 1
89     case -n
90             shift; nopt = 1 
91     case -i
92             shift; iopt = 1; 
93     case -d
94             shift; dopt = 1;
95     case -a
96             shift; aopt = 1; dopt = 1;
97     case --
98             shift; break;
99     }
100 }
101
102 ~ $#* 0  && {echo usage: acleandir [-rnvia] dir; exit 1}
103
104 [  -d  $1 ] || {echo >[1=2] acleandir: $1 not a directory; exit 2}
105
106 doit $1
107
108