fix the io failure for hotplug-in device
This commit is contained in:
@@ -126,7 +126,14 @@ void waybar::modules::Battery::refreshBatteries() {
|
|||||||
// Ignore non-system power supplies unless explicitly requested
|
// Ignore non-system power supplies unless explicitly requested
|
||||||
if (!bat_defined && fs::exists(node.path() / "scope")) {
|
if (!bat_defined && fs::exists(node.path() / "scope")) {
|
||||||
std::string scope;
|
std::string scope;
|
||||||
|
try{
|
||||||
|
//for hotplug-in device, access it is always unstable because you may remove the device anytime
|
||||||
|
//so just allow failure happen and do nothing
|
||||||
std::ifstream(node.path()/"scope")>>scope;
|
std::ifstream(node.path()/"scope")>>scope;
|
||||||
|
}catch(const std::ifstream::failure& e){
|
||||||
|
scope.clear();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (g_ascii_strcasecmp(scope.data(), "device") == 0) {
|
if (g_ascii_strcasecmp(scope.data(), "device") == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user