From 63d3a4f7766337652a91fba3978bf3aa634538e3 Mon Sep 17 00:00:00 2001
From: Jorge Camarero Vera <jorge.camarero@cern.ch>
Date: Fri, 7 Jan 2022 17:08:11 +0100
Subject: [PATCH] Resolve "cta-taped should set the state to DOWN when machine
 rebooting"

---
 ReleaseNotes.md                        | 1 +
 scheduler/TapeDrivesCatalogueState.cpp | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/ReleaseNotes.md b/ReleaseNotes.md
index 77d32b2346..ddee6bd04f 100644
--- a/ReleaseNotes.md
+++ b/ReleaseNotes.md
@@ -10,6 +10,7 @@
 
 ## Bug fixes
 - cta/CTA#1092 - Fix overflow error with drive state latestBandwith causing cta frontend crash
+- cta/CTA#501 - Fix disappearing reason when TapeDrive is reading or writing
 
 # v4.4.0-1
 
diff --git a/scheduler/TapeDrivesCatalogueState.cpp b/scheduler/TapeDrivesCatalogueState.cpp
index dcdd6cb9ef..23f88c6d63 100644
--- a/scheduler/TapeDrivesCatalogueState.cpp
+++ b/scheduler/TapeDrivesCatalogueState.cpp
@@ -276,7 +276,9 @@ void TapeDrivesCatalogueState::setDriveUpOrMaybeDown(common::dataStructures::Tap
   auto targetStatus = common::dataStructures::DriveStatus::Up;
   if (!driveState.desiredUp) {
     driveState.driveStatus = common::dataStructures::DriveStatus::Down;
-    driveState.reasonUpDown = inputs.reason;
+    if (!driveState.reasonUpDown) {
+      driveState.reasonUpDown = inputs.reason;
+    }
   }
   // If we were already up (or down), then we only update the last update time.
   if (driveState.driveStatus == targetStatus) {
-- 
GitLab