linux: Fix reading capacity_level with newer libgudev

Newer development versions of libgudev now strip the linefeeds by
themselves, so fix our naive linefeed-stripping which munched on the
last character of the string if there was no linefeed.

Could not find a percentage for capacity level 'Ful'

See https://gitlab.gnome.org/GNOME/libgudev/-/merge_requests/26
This commit is contained in:
Bastien Nocera 2022-09-02 18:07:47 +02:00
parent 5c8e74b76b
commit 6bfe66a390

View file

@ -215,7 +215,6 @@ sysfs_get_capacity_level (GUdevDevice *native,
{ "Full", 100.0, UP_DEVICE_LEVEL_FULL },
{ "Unknown", 50.0, UP_DEVICE_LEVEL_UNKNOWN }
};
guint len;
g_return_val_if_fail (level != NULL, -1.0);
@ -226,14 +225,12 @@ sysfs_get_capacity_level (GUdevDevice *native,
}
*level = UP_DEVICE_LEVEL_UNKNOWN;
str = g_strdup (g_udev_device_get_sysfs_attr_uncached (native, "capacity_level"));
str = g_strchomp (g_strdup (g_udev_device_get_sysfs_attr_uncached (native, "capacity_level")));
if (!str) {
g_debug ("Failed to read capacity_level!");
return ret;
}
len = strlen(str);
str[len -1] = '\0';
for (i = 0; i < G_N_ELEMENTS(levels); i++) {
if (strcmp (levels[i].str, str) == 0) {
ret = levels[i].percentage;