]>
diplodocus.org Git - nmh/blob - sbr/seq_save.c
30dcbdd3bd01646cade03e9bbca4cfade4f29947
1 /* seq_save.c -- 1) synchronize sequences
2 * -- 2) save public sequences
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
11 #include <h/signals.h>
12 #include "lock_file.h"
17 * 1. If sequence is public and folder is readonly,
18 * then change it to be private
19 * 2a. If sequence is public, then add it to the sequences file
20 * in folder (name specified by mh-sequences profile entry).
21 * 2b. If sequence is private, then add it to the
26 seq_save (struct msgs
*mp
)
29 char flags
, *cp
, attr
[BUFSIZ
], seqfile
[PATH_MAX
];
33 /* check if sequence information has changed */
34 if (!(mp
->msgflags
& SEQMOD
)) {
36 lkfclosedata (mp
->seqhandle
, mp
->seqname
);
43 mp
->msgflags
&= ~SEQMOD
;
46 flags
= mp
->msgflags
; /* record folder flags */
49 * If no mh-sequences file is defined, or if a mh-sequences file
50 * is defined but empty (*mh_seq == '\0'), then pretend folder
51 * is readonly. This will force all sequences to be private.
53 if (mh_seq
== NULL
|| *mh_seq
== '\0')
56 snprintf (seqfile
, sizeof(seqfile
), "%s/%s", mp
->foldpath
, mh_seq
);
58 for (i
= 0; i
< svector_size (mp
->msgattrs
); i
++) {
59 snprintf (attr
, sizeof(attr
), "atr-%s-%s",
60 svector_at (mp
->msgattrs
, i
), mp
->foldpath
);
62 /* get space separated list of sequence ranges */
63 if (!(cp
= seq_list(mp
, svector_at (mp
->msgattrs
, i
)))) {
64 context_del (attr
); /* delete sequence from context */
68 if (is_readonly(mp
) || is_seq_private(mp
, i
)) {
73 context_replace (attr
, cp
); /* update sequence in context */
78 context_del (attr
); /* delete sequence from context */
81 int failed_to_lock
= 0;
84 * Attempt to open file for public sequences.
85 * If that fails (probably because folder is
86 * readonly), then make sequence private.
95 if (ftruncate(fileno(fp
), 0) < 0) {
96 advise ("sequence file", "ftruncate");
98 } else if ((fp
= lkfopendata (seqfile
, "w", &failed_to_lock
))
100 && (m_unlink (seqfile
) == -1 ||
101 (fp
= lkfopendata (seqfile
, "w", &failed_to_lock
))
103 if (failed_to_lock
) {
104 admonish (attr
, "unable to lock");
106 admonish (attr
, "unable to write");
111 /* block a few signals */
113 sigaddset(&set
, SIGHUP
);
114 sigaddset(&set
, SIGINT
);
115 sigaddset(&set
, SIGQUIT
);
116 sigaddset(&set
, SIGTERM
);
117 sigprocmask (SIG_BLOCK
, &set
, &oset
);
119 fprintf (fp
, "%s: %s\n", svector_at (mp
->msgattrs
, i
), cp
);
124 lkfclosedata (fp
, seqfile
);
125 sigprocmask (SIG_SETMASK
, &oset
, &set
); /* reset signal mask */
128 * If folder is not readonly, and we didn't save any
129 * public sequences, then remove that file.
131 if (!is_readonly(mp
))
132 (void) m_unlink (seqfile
);
136 * Reset folder flag, since we may be
137 * pretending that folder is readonly.
139 mp
->msgflags
= flags
;