File: remove

package info (click to toggle)
simrisc 16.05.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,568 kB
  • sloc: cpp: 6,877; fortran: 665; makefile: 112; ansic: 112; sh: 107
file content (39 lines) | stat: -rwxr-xr-x 630 bytes parent folder | download | duplicates (10)
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
#!/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