From f1e799127916f9e17679c207cfe563534e8d9915 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Wed, 1 Jun 2016 16:06:36 +0200 Subject: [PATCH] fix(battery): Check file existance --- src/modules/battery.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index a88aa088..088faaf2 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -53,8 +53,16 @@ BatteryModule::BatteryModule(const std::string& name_) : InotifyModule(name_) this->label_full = drawtypes::get_optional_config_label( name(), get_tag_name(TAG_LABEL_FULL), "%percentage%"); - this->watch(string::replace(PATH_BATTERY_CAPACITY, "%battery%", this->battery), InotifyEvent::ACCESSED); - this->watch(string::replace(PATH_ADAPTER_STATUS, "%adapter%", this->adapter), InotifyEvent::ACCESSED); + const auto capacity_path = string::replace(PATH_BATTERY_CAPACITY, "%battery%", this->battery); + const auto adapter_path = string::replace(PATH_ADAPTER_STATUS, "%adapter%", this->adapter); + + if (!io::file::exists(capacity_path)) + throw ModuleError("[BatteryModule] The file \""+ capacity_path +"\" does not exist"); + if (!io::file::exists(adapter_path)) + throw ModuleError("[BatteryModule] The file \""+ adapter_path +"\" does not exist"); + + this->watch(capacity_path, InotifyEvent::ACCESSED); + this->watch(adapter_path, InotifyEvent::ACCESSED); } void BatteryModule::start()