File: force-delete

package info (click to toggle)
bup 0.33.9-1.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,712 kB
  • sloc: python: 15,897; sh: 5,764; ansic: 2,965; pascal: 669; makefile: 21
file content (32 lines) | stat: -rwxr-xr-x 629 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/env bash

set -o pipefail

# Try *hard* to delete $@.  Among other things, some systems have
# r-xr-xr-x for root and other system dirs.

rc=0
rm -rf "$@" # Maybe we'll get lucky.
for f in "$@"; do
    test -e "$f" || continue
    if test "$(type -p setfacl)"; then
        setfacl -Rb "$f"
    fi
    if test "$(type -p chattr)"; then
        chattr -R -aisu "$f"
    fi
    chmod -R u+rwX "$f"
    rm -r "$f"
    if test -e "$f"; then
        rc=1
        find "$f" -ls
        lsattr -aR "$f"
        getfacl -R "$f"
    fi
done

if test "$rc" -ne 0; then
    echo "Failed to delete everything" 1>&2
fi

exit "$rc"