From 7191364c88e8ee543c122da1565a136fd8fe6621 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Sat, 28 Aug 2021 08:34:50 +0200 Subject: [PATCH] Improved error message if ID is already in use --- src/raspberrypi/rascsi.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/raspberrypi/rascsi.cpp b/src/raspberrypi/rascsi.cpp index 9b4ddeb2..17d27b45 100644 --- a/src/raspberrypi/rascsi.cpp +++ b/src/raspberrypi/rascsi.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -65,7 +66,8 @@ static void *MonThread(void *param); vector log_levels; string current_log_level; // Some versions of spdlog do not support get_log_level() string default_image_folder; -set files_in_use; +typedef pair full_id; +map files_in_use; DeviceFactory& device_factory = DeviceFactory::instance(); //--------------------------------------------------------------------------- @@ -758,13 +760,16 @@ bool ProcessCmd(int fd, const PbDeviceDefinition& pbDevice, const PbOperation cm } } - if (files_in_use.find(filepath.GetPath()) != files_in_use.end()) { + const string path = filepath.GetPath(); + if (files_in_use.find(path) != files_in_use.end()) { delete device; - return ReturnStatus(fd, false, "Image file '" + filename + "' is already in use"); + const auto& full_id = files_in_use[path]; + error << "Image file '" << filename << "' is already used by ID " << full_id.first << ", unit " << full_id.second; + return ReturnStatus(fd, false, error); } - files_in_use.insert(filepath.GetPath()); + files_in_use[path] = make_pair(device->GetId(), device->GetLun()); } // Stop the dry run here, before permanently modifying something