mirror of
https://github.com/systemd/systemd
synced 2024-09-06 16:56:43 +00:00
sd-device: make sd_device_has_current_tag() and friends compatible with database version 0
This commit is contained in:
parent
58b30ada0b
commit
6ece7cd2b7
|
@ -1444,11 +1444,26 @@ _public_ const char *sd_device_get_tag_next(sd_device *device) {
|
|||
return v;
|
||||
}
|
||||
|
||||
static bool device_database_supports_current_tags(sd_device *device) {
|
||||
assert(device);
|
||||
|
||||
(void) device_read_db(device);
|
||||
|
||||
/* The current tags (saved in Q field) feature is implemented in database version 1.
|
||||
* If the database version is 0, then the tags (NOT current tags, saved in G field) are not
|
||||
* sticky. Thus, we can safely bypass the operations for the current tags (Q) to tags (G). */
|
||||
|
||||
return device->database_version >= 1;
|
||||
}
|
||||
|
||||
_public_ const char *sd_device_get_current_tag_first(sd_device *device) {
|
||||
void *v;
|
||||
|
||||
assert_return(device, NULL);
|
||||
|
||||
if (!device_database_supports_current_tags(device))
|
||||
return sd_device_get_tag_first(device);
|
||||
|
||||
(void) device_read_db(device);
|
||||
|
||||
device->current_tags_iterator_generation = device->tags_generation;
|
||||
|
@ -1463,6 +1478,9 @@ _public_ const char *sd_device_get_current_tag_next(sd_device *device) {
|
|||
|
||||
assert_return(device, NULL);
|
||||
|
||||
if (!device_database_supports_current_tags(device))
|
||||
return sd_device_get_tag_next(device);
|
||||
|
||||
(void) device_read_db(device);
|
||||
|
||||
if (device->current_tags_iterator_generation != device->tags_generation)
|
||||
|
@ -1765,6 +1783,9 @@ _public_ int sd_device_has_current_tag(sd_device *device, const char *tag) {
|
|||
assert_return(device, -EINVAL);
|
||||
assert_return(tag, -EINVAL);
|
||||
|
||||
if (!device_database_supports_current_tags(device))
|
||||
return sd_device_has_tag(device, tag);
|
||||
|
||||
(void) device_read_db(device);
|
||||
|
||||
return set_contains(device->current_tags, tag);
|
||||
|
|
Loading…
Reference in a new issue