summaryrefslogtreecommitdiff
path: root/usr.bin/vi/build/recover
blob: fb3e5f9f4085c0020e6c41a063c8b529bef349f7 (plain)
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
41
42
43
44
45
46
47
48
49
50
#!/bin/sh -
#
#	$OpenBSD: recover,v 1.1 1997/07/27 23:29:12 downsj Exp $
#	@(#)recover.in	8.8 (Berkeley) 10/10/96
#
# Script to recover nvi edit sessions.
#
RECDIR="/var/tmp/vi.recover"
SENDMAIL="/usr/sbin/sendmail"

echo 'Recovering nvi editor sessions.'

# Check editor backup files.
vibackup=`echo $RECDIR/vi.*`
if [ "$vibackup" != "$RECDIR/vi.*" ]; then
	for i in $vibackup; do
		# Only test files that are readable.
		if test ! -r $i; then
			continue
		fi

		# Unmodified nvi editor backup files either have the
		# execute bit set or are zero length.  Delete them.
		if test -x $i -o ! -s $i; then
			rm $i
		fi
	done
fi

# It is possible to get incomplete recovery files, if the editor crashes
# at the right time.
virecovery=`echo $RECDIR/recover.*`
if [ "$virecovery" != "$RECDIR/recover.*" ]; then
	for i in $virecovery; do
		# Only test files that are readable.
		if test ! -r $i; then
			continue
		fi

		# Delete any recovery files that are zero length, corrupted,
		# or that have no corresponding backup file.  Else send mail
		# to the user.
		recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
		if test -n "$recfile" -a -s "$recfile"; then
			$SENDMAIL -t < $i
		else
			rm $i
		fi
	done
fi