the script used to extract a release
[nvi.git] / ex / ex_preserve.c
blobdc62fa3f994b591308b796ec0cd59a8bd01b5b20
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.14 2000/07/14 14:29:20 skimo Exp $ (Berkeley) $Date: 2000/07/14 14:29:20 $";
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;
76 char *np;
77 size_t nlen;
79 ap = cmdp->argv[0];
81 /* Set the alternate file name. */
82 INT2CHAR(sp, ap->bp, ap->len+1, np, nlen);
83 set_alt_name(sp, np);
86 * Check for modifications. Autowrite did not historically
87 * affect :recover.
89 if (file_m2(sp, FL_ISSET(cmdp->iflags, E_C_FORCE)))
90 return (1);
92 /* Get a file structure for the file. */
93 INT2CHAR(sp, ap->bp, ap->len+1, np, nlen);
94 if ((frp = file_add(sp, np)) == NULL)
95 return (1);
97 /* Set the recover bit. */
98 F_SET(frp, FR_RECOVER);
100 /* Switch files. */
101 if (file_init(sp, frp, NULL, FS_SETALT |
102 (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
103 return (1);
105 F_SET(sp, SC_FSWITCH);
106 return (0);