X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/e491542da563673b49c6f6df9948ffaffbeed4fb..d7a9b5aa35f81e680a54a2f7c2b7dab749812cef:/sbr/seq_save.c diff --git a/sbr/seq_save.c b/sbr/seq_save.c index 83753afb..8ac30867 100644 --- a/sbr/seq_save.c +++ b/sbr/seq_save.c @@ -77,6 +77,8 @@ priv: context_del (attr); /* delete sequence from context */ if (!fp) { + int failed_to_lock = 0; + /* * Attempt to open file for public sequences. * If that fails (probably because folder is @@ -89,11 +91,19 @@ priv: free(mp->seqname); mp->seqname = NULL; rewind(fp); - ftruncate(fileno(fp), 0); - } else if ((fp = lkfopendata (seqfile, "w")) == NULL - && (unlink (seqfile) == -1 || - (fp = lkfopendata (seqfile, "w")) == NULL)) { - admonish (attr, "unable to write"); + if (ftruncate(fileno(fp), 0) < 0) { + advise ("sequence file", "ftruncate"); + } + } else if ((fp = lkfopendata (seqfile, "w", &failed_to_lock)) + == NULL + && (m_unlink (seqfile) == -1 || + (fp = lkfopendata (seqfile, "w", &failed_to_lock)) + == NULL)) { + if (failed_to_lock) { + admonish (attr, "unable to lock"); + } else { + admonish (attr, "unable to write"); + } goto priv; } @@ -118,7 +128,7 @@ priv: * public sequences, then remove that file. */ if (!is_readonly(mp)) - unlink (seqfile); + (void) m_unlink (seqfile); } /*