File: remove

package info (click to toggle)
stealth 4.04.00-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,540 kB
  • sloc: cpp: 2,759; sh: 151; makefile: 111; ansic: 52
file content (40 lines) | stat: -rwxr-xr-x 632 bytes parent folder | download | duplicates (50)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash

g_echo=$2

rm_f()
{
    [ $g_echo -ne 0 ] && echo rm $1
    rm -f $1
}

rm_dir()
{
    [ $g_echo -ne 0 ] && echo rmdir $1
    rmdir --ignore-fail-on-non-empty -p $1
}
 

IFS="
"

for line in `cat $1`
do
    field1=`echo $line | awk '{printf $1}'`
    field2=`echo $line | awk '{printf $2}'`

    if [ $field1 == "link" ] ; then
        rm_f $field2
    elif [ $field1 == "dir" ] ; then
	rm_dir $field2
    elif [ -e "$field2" ] ; then
        if [ "$field1" != "`md5sum $field2 | awk '{printf $1}'`" ] ; then
            echo $field2 changed, not removed
        else
	    rm_f $field2
        fi
    fi
done

rm_f $1