Clean up deleted files.
This commit is contained in:
parent
a8078f319e
commit
24249baa85
@ -1,10 +0,0 @@
|
||||
# $Id: Makefile,v 1.4 1993/08/02 17:50:31 mycroft Exp $
|
||||
|
||||
PROG= elvispreserve
|
||||
CFLAGS+=-I${.CURDIR}/../../usr.bin/elvis
|
||||
BINOWN= root
|
||||
BINMODE=4755
|
||||
MAN8=elvispreserve.0
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
.PATH: ${.CURDIR}/../../usr.bin/elvis
|
@ -1,55 +0,0 @@
|
||||
.\" $Id: elvispreserve.8,v 1.4 1993/08/02 17:50:32 mycroft Exp $ -*- nroff -*-
|
||||
.TH ELVISPRESERVE 8
|
||||
.SH NAME
|
||||
elvispreserve - Preserve the the modified version of a file after a crash.
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
\fB\fBelvispreserve\fP ["-\fIwhy elvis died\fP"] /tmp/\fIfilename\fP...
|
||||
\fB\fBelvispreserve\fP -R /tmp/\fIfilename\fP...
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
\fIelvispreserve\fP preserves your edited text after \fIelvis\fP dies.
|
||||
The text can be recovered later, via the \fIelvispreserve\fP program.
|
||||
.PP
|
||||
For UNIX-like systems,
|
||||
you should never need to run this program from the command line.
|
||||
It is run automatically when \fIelvis\fP is about to die,
|
||||
and it should be run (via /etc/rc) when the computer is booted.
|
||||
THAT'S ALL!
|
||||
.PP
|
||||
For non-UNIX systems such as MS-DOS, you can either use \fIelvispreserve\fP
|
||||
the same way as under UNIX systems (by running it from your AUTOEXEC.BAT file),
|
||||
or you can run it separately with the "-R" flag to recover the files
|
||||
in one step.
|
||||
.PP
|
||||
If you're editing a file when \fIelvis\fP dies
|
||||
(due to a bug, system crash, power failure, etc.)
|
||||
then \fIelvispreserve\fP will preserve the most recent version of your text.
|
||||
The preserved text is stored in a special directory; it does NOT overwrite
|
||||
your text file automatically.
|
||||
.PP
|
||||
\fIelvispreserve\fP will send mail to any user whose work it preserves,
|
||||
if your operating system normally supports mail.
|
||||
.SH FILES
|
||||
.IP /tmp/elv*
|
||||
The temporary file that \fIelvis\fP was using when it died.
|
||||
.IP /var/preserve/p*
|
||||
The text that is preserved by \fIelvispreserve\fP.
|
||||
.IP /var/preserve/Index
|
||||
A text file which lists the names of all preserved files, and the names
|
||||
of the /var/preserve/p* files which contain their preserved text.
|
||||
.SH BUGS
|
||||
.PP
|
||||
Due to the permissions on the /var/preserve directory, on UNIX systems
|
||||
\fIelvispreserve\fP must be run as superuser.
|
||||
This is accomplished by making the \fIelvispreserve\fP executable be owned by "root"
|
||||
and turning on its "set user id" bit.
|
||||
.PP
|
||||
If you're editing a nameless buffer when \fIelvis\fP dies, then \fIelvispreserve\fP will pretend
|
||||
that the file was named "foo".
|
||||
.SH AUTHOR
|
||||
.nf
|
||||
Steve Kirkendall
|
||||
kirkenda@cs.pdx.edu
|
||||
.fi
|
@ -1,317 +0,0 @@
|
||||
/* elvprsv.c */
|
||||
|
||||
/* Author:
|
||||
* Steve Kirkendall
|
||||
* 14407 SW Teal Blvd. #C
|
||||
* Beaverton, OR 97005
|
||||
* kirkenda@cs.pdx.edu
|
||||
*/
|
||||
|
||||
|
||||
/* This file contains the portable sources for the "elvprsv" program.
|
||||
* "Elvprsv" is run by Elvis when Elvis is about to die. It is also
|
||||
* run when the computer boots up. It is not intended to be run directly
|
||||
* by the user, ever.
|
||||
*
|
||||
* Basically, this program does the following four things:
|
||||
* - It extracts the text from the temporary file, and places the text in
|
||||
* a file in the /usr/preserve directory.
|
||||
* - It adds a line to the /usr/preserve/Index file, describing the file
|
||||
* that it just preserved.
|
||||
* - It removes the temporary file.
|
||||
* - It sends mail to the owner of the file, saying that the file was
|
||||
* preserved, and how it can be recovered.
|
||||
*
|
||||
* The /usr/preserve/Index file is a log file that contains one line for each
|
||||
* file that has ever been preserved. Each line of this file describes one
|
||||
* preserved file. The first word on the line is the name of the file that
|
||||
* contains the preserved text. The second word is the full pathname of the
|
||||
* file that was being edited; for anonymous buffers, this is the directory
|
||||
* name plus "/foo".
|
||||
*
|
||||
* If elvprsv's first argument (after the command name) starts with a hyphen,
|
||||
* then the characters after the hyphen are used as a description of when
|
||||
* the editor went away. This is optional.
|
||||
*
|
||||
* The remaining arguments are all the names of temporary files that are
|
||||
* to be preserved. For example, on a UNIX system, the /etc/rc file might
|
||||
* invoke it this way:
|
||||
*
|
||||
* elvprsv "-the system went down" /tmp/elv_*.*
|
||||
*
|
||||
* This file contains only the portable parts of the preserve program.
|
||||
* It must #include a system-specific file. The system-specific file is
|
||||
* expected to define the following functions:
|
||||
*
|
||||
* char *ownername(char *filename) - returns name of person who owns file
|
||||
*
|
||||
* void mail(char *user, char *name, char *when)
|
||||
* - tell user that file was preserved
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char elvispreserve_rcsid[] = "$Id: elvispreserve.c,v 1.4 1993/08/10 00:10:17 mycroft Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "config.h"
|
||||
#include "vi.h"
|
||||
|
||||
/* We include ctype.c here (instead of including just ctype.h and linking
|
||||
* with ctype.o) because on some systems ctype.o will have been compiled in
|
||||
* "large model" and the elvprsv program is to be compiled in "small model"
|
||||
* You can't mix models. By including ctype.c here, we can avoid linking
|
||||
* with ctype.o.
|
||||
*/
|
||||
#include "ctype.c"
|
||||
|
||||
void preserve P_((char *, char *));
|
||||
void main P_((int, char **));
|
||||
|
||||
#if AMIGA
|
||||
BLK tmpblk;
|
||||
# include "amiwild.c"
|
||||
# include "amiprsv.c"
|
||||
#endif
|
||||
|
||||
#if OSK
|
||||
# undef sprintf
|
||||
#endif
|
||||
|
||||
#if ANY_UNIX || OSK
|
||||
# include "prsvunix.c"
|
||||
#endif
|
||||
|
||||
#if MSDOS || TOS
|
||||
# include "prsvdos.c"
|
||||
# define WILDCARD_NO_MAIN
|
||||
# include "wildcard.c"
|
||||
#endif
|
||||
|
||||
|
||||
BLK buf;
|
||||
BLK hdr;
|
||||
BLK name;
|
||||
int rewrite_now; /* boolean: should we send text directly to orig file? */
|
||||
|
||||
|
||||
|
||||
/* This function preserves a single file, and announces its success/failure
|
||||
* via an e-mail message.
|
||||
*/
|
||||
void preserve(tname, when)
|
||||
char *tname; /* name of a temp file to be preserved */
|
||||
char *when; /* description of when the editor died */
|
||||
{
|
||||
int infd; /* fd used for reading from the temp file */
|
||||
FILE *outfp; /* fp used for writing to the recovery file */
|
||||
FILE *index; /* fp used for appending to index file */
|
||||
char outname[100]; /* the name of the recovery file */
|
||||
char *user; /* name of the owner of the temp file */
|
||||
#if AMIGA
|
||||
char *prsvdir;
|
||||
#endif
|
||||
int i;
|
||||
|
||||
/* open the temp file */
|
||||
infd = open(tname, O_RDONLY|O_BINARY);
|
||||
if (infd < 0)
|
||||
{
|
||||
/* if we can't open the file, then we should assume that
|
||||
* the filename contains wildcard characters that weren't
|
||||
* expanded... and also assume that they weren't expanded
|
||||
* because there are no files that need to be preserved.
|
||||
* THEREFORE... we should silently ignore it.
|
||||
* (Or loudly ignore it if the user was using -R)
|
||||
*/
|
||||
if (rewrite_now)
|
||||
{
|
||||
perror(tname);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* read the header and name from the file */
|
||||
if (read(infd, hdr.c, BLKSIZE) != BLKSIZE
|
||||
|| read(infd, name.c, BLKSIZE) != BLKSIZE)
|
||||
{
|
||||
/* something wrong with the file - sorry */
|
||||
fprintf(stderr, "%s: truncated header blocks\n", tname);
|
||||
close(infd);
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the filename block contains an empty string, then Elvis was
|
||||
* only keeping the temp file around because it contained some text
|
||||
* that was needed for a named cut buffer. The user doesn't care
|
||||
* about that kind of temp file, so we should silently delete it.
|
||||
*/
|
||||
if (name.c[0] == '\0' && name.c[1] == '\177')
|
||||
{
|
||||
close(infd);
|
||||
unlink(tname);
|
||||
return;
|
||||
}
|
||||
|
||||
/* If there are no text blocks in the file, then we must've never
|
||||
* really started editing. Discard the file.
|
||||
*/
|
||||
if (hdr.n[1] == 0)
|
||||
{
|
||||
close(infd);
|
||||
unlink(tname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (rewrite_now)
|
||||
{
|
||||
/* we don't need to open the index file */
|
||||
index = (FILE *)0;
|
||||
|
||||
/* make sure we can read every block! */
|
||||
for (i = 1; i < MAXBLKS && hdr.n[i]; i++)
|
||||
{
|
||||
lseek(infd, (long)hdr.n[i] * (long)BLKSIZE, 0);
|
||||
if (read(infd, buf.c, BLKSIZE) != BLKSIZE
|
||||
|| buf.c[0] == '\0')
|
||||
{
|
||||
/* messed up header */
|
||||
fprintf(stderr, "%s: unrecoverable -- header trashed\n", name.c);
|
||||
close(infd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* open the user's file for writing */
|
||||
outfp = fopen(name.c, "w");
|
||||
if (!outfp)
|
||||
{
|
||||
perror(name.c);
|
||||
close(infd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* open/create the index file */
|
||||
index = fopen(PRSVINDEX, "a");
|
||||
if (!index)
|
||||
{
|
||||
perror(PRSVINDEX);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* should be at the end of the file already, but MAKE SURE */
|
||||
fseek(index, 0L, 2);
|
||||
|
||||
/* create the recovery file in the PRESVDIR directory */
|
||||
#if AMIGA
|
||||
prsvdir = &PRSVDIR[strlen(PRSVDIR) - 1];
|
||||
if (*prsvdir == '/' || *prsvdir == ':')
|
||||
{
|
||||
sprintf(outname, "%sp%ld", PRSVDIR, ftell(index));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
sprintf(outname, "%s%cp%ld", PRSVDIR, SLASH, ftell(index));
|
||||
outfp = fopen(outname, "w");
|
||||
if (!outfp)
|
||||
{
|
||||
perror(outname);
|
||||
close(infd);
|
||||
fclose(index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* write the text of the file out to the recovery file */
|
||||
for (i = 1; i < MAXBLKS && hdr.n[i]; i++)
|
||||
{
|
||||
lseek(infd, (long)hdr.n[i] * (long)BLKSIZE, 0);
|
||||
if (read(infd, buf.c, BLKSIZE) != BLKSIZE
|
||||
|| buf.c[0] == '\0')
|
||||
{
|
||||
/* messed up header */
|
||||
fprintf(stderr, "%s: unrecoverable -- header trashed\n", name.c);
|
||||
fclose(outfp);
|
||||
close(infd);
|
||||
if (index)
|
||||
{
|
||||
fclose(index);
|
||||
}
|
||||
unlink(outname);
|
||||
return;
|
||||
}
|
||||
fputs(buf.c, outfp);
|
||||
}
|
||||
|
||||
/* add a line to the index file */
|
||||
if (index)
|
||||
{
|
||||
fprintf(index, "%s %s\n", outname, name.c);
|
||||
}
|
||||
|
||||
/* close everything */
|
||||
close(infd);
|
||||
fclose(outfp);
|
||||
if (index)
|
||||
{
|
||||
fclose(index);
|
||||
}
|
||||
|
||||
/* Are we doing this due to something more frightening than just
|
||||
* a ":preserve" command?
|
||||
*/
|
||||
if (*when)
|
||||
{
|
||||
/* send a mail message */
|
||||
mail(ownername(tname), name.c, when);
|
||||
|
||||
/* remove the temp file -- the editor has died already */
|
||||
unlink(tname);
|
||||
}
|
||||
}
|
||||
|
||||
void main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int i;
|
||||
char *when = "the editor went away";
|
||||
|
||||
#if MSDOS || TOS
|
||||
/* expand any wildcards in the command line */
|
||||
_ct_init("");
|
||||
argv = wildexpand(&argc, argv);
|
||||
#endif
|
||||
|
||||
/* do we have a "-c", "-R", or "-when elvis died" argument? */
|
||||
i = 1;
|
||||
if (argc >= i + 1 && !strcmp(argv[i], "-R"))
|
||||
{
|
||||
rewrite_now = 1;
|
||||
when = "";
|
||||
i++;
|
||||
#if ANY_UNIX
|
||||
setuid(geteuid());
|
||||
#endif
|
||||
}
|
||||
#if OSK
|
||||
else
|
||||
{
|
||||
setuid(0);
|
||||
}
|
||||
#endif
|
||||
if (argc >= i + 1 && argv[i][0] == '-')
|
||||
{
|
||||
when = argv[i] + 1;
|
||||
i++;
|
||||
}
|
||||
|
||||
/* preserve everything we're supposed to */
|
||||
while (i < argc)
|
||||
{
|
||||
preserve(argv[i], when);
|
||||
i++;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user