*** empty log message ***
[nvi.git] / ex / ex_preserve.c
blobd08f28764d51fc814757f62403e1680a16ae700c
1 /*-
2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: ex_preserve.c,v 10.13 2000/04/21 19:00:36 skimo Exp $ (Berkeley) $Date: 2000/04/21 19:00:36 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
20 #include <errno.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "../common/common.h"
28 * ex_preserve -- :pre[serve]
29 * Push the file to recovery.
31 * PUBLIC: int ex_preserve __P((SCR *, EXCMD *));
33 int
34 ex_preserve(sp, cmdp)
35 SCR *sp;
36 EXCMD *cmdp;
38 db_recno_t lno;
40 NEEDFILE(sp, cmdp);
42 if (!F_ISSET(sp->ep, F_RCV_ON)) {
43 msgq(sp, M_ERR, "142|Preservation of this file not possible");
44 return (1);
47 /* If recovery not initialized, do so. */
48 if (F_ISSET(sp->ep, F_FIRSTMODIFY) && rcv_init(sp))
49 return (1);
51 /* Force the file to be read in, in case it hasn't yet. */
52 if (db_last(sp, &lno))
53 return (1);
55 /* Sync to disk. */
56 if (rcv_sync(sp, RCV_SNAPSHOT))
57 return (1);
59 msgq(sp, M_INFO, "143|File preserved");
60 return (0);
64 * ex_recover -- :rec[over][!] file
65 * Recover the file.
67 * PUBLIC: int ex_recover __P((SCR *, EXCMD *));
69 int
70 ex_recover(sp, cmdp)
71 SCR *sp;
72 EXCMD *cmdp;
74 ARGS *ap;
75 FREF *frp;
77 ap = cmdp->argv[0];
79 /* Set the alternate file name. */
80 set_alt_name(sp, ap->bp);
83 * Check for modifications. Autowrite did not historically
84 * affect :recover.
86 if (file_m2(sp, FL_ISSET(cmdp->iflags, E_C_FORCE)))
87 return (1);
89 /* Get a file structure for the file. */
90 if ((frp = file_add(sp, ap->bp)) == NULL)
91 return (1);
93 /* Set the recover bit. */
94 F_SET(frp, FR_RECOVER);
96 /* Switch files. */
97 if (file_init(sp, frp, NULL, FS_SETALT |
98 (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
99 return (1);
101 F_SET(sp, SC_FSWITCH);
102 return (0);