- if (!job_cancelled(jcr) && ok) {
- jcr->JobStatus = JS_Terminated;
- } else if (!ok) {
- jcr->JobStatus = JS_ErrorTerminated;
- }
- if (!write_session_label(jcr, block, EOS_LABEL)) {
- Jmsg1(jcr, M_FATAL, 0, _("Error writting end session label. ERR=%s\n"),
- strerror_dev(dev));
- ok = FALSE;
+ set_jcr_job_status(jcr, ok?JS_Terminated:JS_ErrorTerminated);
+
+ Dmsg1(200, "Write session label JobStatus=%d\n", jcr->JobStatus);
+
+ /*
+ * If !OK, check if we can still write. This may not be the case
+ * if we are at the end of the tape or we got a fatal I/O error.
+ */
+ if (ok || dev_can_write(dev)) {
+ if (!write_session_label(jcr, block, EOS_LABEL)) {
+ Jmsg1(jcr, M_FATAL, 0, _("Error writting end session label. ERR=%s\n"),
+ strerror_dev(dev));
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
+ ok = false;
+ }
+ Dmsg0(90, "back from write_end_session_label()\n");
+ /* Flush out final partial block of this session */
+ if (!write_block_to_device(jcr->dcr, block)) {
+ Dmsg0(100, _("Set ok=FALSE after write_block_to_device.\n"));
+ set_jcr_job_status(jcr, JS_ErrorTerminated);
+ ok = false;
+ }