mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 06:28:05 +02:00
keyfile: don't require a path when creating a keyfile connection
This commit is contained in:
parent
830f65fc58
commit
9d94000c69
3 changed files with 18 additions and 19 deletions
|
|
@ -41,8 +41,8 @@ typedef struct {
|
|||
} NMKeyfileConnectionPrivate;
|
||||
|
||||
NMKeyfileConnection *
|
||||
nm_keyfile_connection_new (const char *full_path,
|
||||
NMConnection *source,
|
||||
nm_keyfile_connection_new (NMConnection *source,
|
||||
const char *full_path,
|
||||
GError **error)
|
||||
{
|
||||
GObject *object;
|
||||
|
|
@ -51,7 +51,7 @@ nm_keyfile_connection_new (const char *full_path,
|
|||
const char *uuid;
|
||||
gboolean update_unsaved = TRUE;
|
||||
|
||||
g_return_val_if_fail (full_path != NULL, NULL);
|
||||
g_assert (source || full_path);
|
||||
|
||||
/* If we're given a connection already, prefer that instead of re-reading */
|
||||
if (source)
|
||||
|
|
@ -61,6 +61,14 @@ nm_keyfile_connection_new (const char *full_path,
|
|||
if (!tmp)
|
||||
return NULL;
|
||||
|
||||
uuid = nm_connection_get_uuid (NM_CONNECTION (tmp));
|
||||
if (!uuid) {
|
||||
g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
|
||||
"Connection in file %s had no UUID", full_path);
|
||||
g_object_unref (tmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If we just read the connection from disk, it's clearly not Unsaved */
|
||||
update_unsaved = FALSE;
|
||||
}
|
||||
|
|
@ -77,18 +85,8 @@ nm_keyfile_connection_new (const char *full_path,
|
|||
error)) {
|
||||
g_object_unref (object);
|
||||
object = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
uuid = nm_connection_get_uuid (NM_CONNECTION (object));
|
||||
if (!uuid) {
|
||||
g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
|
||||
"Connection in file %s had no UUID", full_path);
|
||||
g_object_unref (object);
|
||||
object = NULL;
|
||||
}
|
||||
|
||||
out:
|
||||
g_object_unref (tmp);
|
||||
return (NMKeyfileConnection *) object;
|
||||
}
|
||||
|
|
@ -150,7 +148,8 @@ do_delete (NMSettingsConnection *connection,
|
|||
{
|
||||
NMKeyfileConnectionPrivate *priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (connection);
|
||||
|
||||
g_unlink (priv->path);
|
||||
if (priv->path)
|
||||
g_unlink (priv->path);
|
||||
|
||||
NM_SETTINGS_CONNECTION_CLASS (nm_keyfile_connection_parent_class)->delete (connection,
|
||||
callback,
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ typedef struct {
|
|||
|
||||
GType nm_keyfile_connection_get_type (void);
|
||||
|
||||
NMKeyfileConnection *nm_keyfile_connection_new (const char *filename,
|
||||
NMConnection *source,
|
||||
NMKeyfileConnection *nm_keyfile_connection_new (NMConnection *source,
|
||||
const char *filename,
|
||||
GError **error);
|
||||
|
||||
const char *nm_keyfile_connection_get_path (NMKeyfileConnection *self);
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ _internal_new_connection (SCPluginKeyfile *self,
|
|||
|
||||
g_return_val_if_fail (full_path != NULL, NULL);
|
||||
|
||||
connection = nm_keyfile_connection_new (full_path, source, error);
|
||||
connection = nm_keyfile_connection_new (source, full_path, error);
|
||||
if (connection) {
|
||||
g_hash_table_insert (priv->connections,
|
||||
(gpointer) nm_connection_get_uuid (NM_CONNECTION (connection)),
|
||||
|
|
@ -197,7 +197,7 @@ dir_changed (GFileMonitor *monitor,
|
|||
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
||||
if (connection) {
|
||||
/* Update */
|
||||
tmp = nm_keyfile_connection_new (full_path, NULL, &error);
|
||||
tmp = nm_keyfile_connection_new (NULL, full_path, &error);
|
||||
if (tmp) {
|
||||
if (!nm_connection_compare (NM_CONNECTION (connection),
|
||||
NM_CONNECTION (tmp),
|
||||
|
|
@ -223,7 +223,7 @@ dir_changed (GFileMonitor *monitor,
|
|||
} else {
|
||||
/* New */
|
||||
PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "updating %s", full_path);
|
||||
tmp = nm_keyfile_connection_new (full_path, NULL, &error);
|
||||
tmp = nm_keyfile_connection_new (NULL, full_path, &error);
|
||||
if (tmp) {
|
||||
/* Connection renames will show as different paths but same UUID */
|
||||
connection = g_hash_table_lookup (priv->connections, nm_connection_get_uuid (NM_CONNECTION (tmp)));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue