mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 08:00:18 +01:00
checkpoint: refactor nm_checkpoint_manager_create() to simplify creating device list
If no device paths are given, we can take the devices directly. We don't need to first create a list of paths, and then look them up by path again to add them to the list.
This commit is contained in:
parent
daf3d5cb53
commit
63e3bff916
1 changed files with 20 additions and 28 deletions
|
|
@ -154,53 +154,45 @@ nm_checkpoint_manager_create (NMCheckpointManager *self,
|
|||
{
|
||||
NMManager *manager;
|
||||
NMCheckpoint *checkpoint;
|
||||
const char *const *dev_paths;
|
||||
gs_unref_ptrarray GPtrArray *devices = NULL;
|
||||
NMDevice *device;
|
||||
const char *path;
|
||||
gs_free const char **device_paths_free = NULL;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (self, FALSE);
|
||||
g_return_val_if_fail (!error || !*error, FALSE);
|
||||
manager = GET_MANAGER (self);
|
||||
|
||||
if (!device_paths || !device_paths[0]) {
|
||||
const char *device_path;
|
||||
const CList *tmp_lst;
|
||||
GPtrArray *paths;
|
||||
devices = g_ptr_array_new ();
|
||||
|
||||
if (!device_paths || !device_paths[0]) {
|
||||
const CList *tmp_lst;
|
||||
|
||||
paths = g_ptr_array_new ();
|
||||
nm_manager_for_each_device (manager, device, tmp_lst) {
|
||||
if (!nm_device_is_real (device))
|
||||
continue;
|
||||
device_path = nm_dbus_object_get_path (NM_DBUS_OBJECT (device));
|
||||
if (device_path)
|
||||
g_ptr_array_add (paths, (gpointer) device_path);
|
||||
nm_assert (nm_dbus_object_get_path (NM_DBUS_OBJECT (device)));
|
||||
g_ptr_array_add (devices, device);
|
||||
}
|
||||
g_ptr_array_add (paths, NULL);
|
||||
device_paths_free = (const char **) g_ptr_array_free (paths, FALSE);
|
||||
device_paths = (const char *const *) device_paths_free;
|
||||
} else if (NM_FLAGS_HAS (flags, NM_CHECKPOINT_CREATE_FLAG_DISCONNECT_NEW_DEVICES)) {
|
||||
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_INVALID_ARGUMENTS,
|
||||
"the DISCONNECT_NEW_DEVICES flag can only be used with an empty device list");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
devices = g_ptr_array_new ();
|
||||
for (dev_paths = device_paths; *dev_paths; dev_paths++) {
|
||||
device = nm_manager_get_device_by_path (manager, *dev_paths);
|
||||
if (!device) {
|
||||
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
|
||||
"device %s does not exist", *dev_paths);
|
||||
return NULL;
|
||||
} else {
|
||||
for (; *device_paths; device_paths++) {
|
||||
device = nm_manager_get_device_by_path (manager, *device_paths);
|
||||
if (!device) {
|
||||
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
|
||||
"device %s does not exist", *device_paths);
|
||||
return NULL;
|
||||
}
|
||||
if (!nm_device_is_real (device)) {
|
||||
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
|
||||
"device %s is not realized", *device_paths);
|
||||
return NULL;
|
||||
}
|
||||
g_ptr_array_add (devices, device);
|
||||
}
|
||||
if (!nm_device_is_real (device)) {
|
||||
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
|
||||
"device %s is not realized", *dev_paths);
|
||||
return NULL;
|
||||
}
|
||||
g_ptr_array_add (devices, device);
|
||||
}
|
||||
|
||||
if (!NM_FLAGS_HAS (flags, NM_CHECKPOINT_CREATE_FLAG_DESTROY_ALL)) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue