repo: Ensure new config doesn't set remotes in separate file

If the new configuration passed to ostree_write_config () tries to
update options for a remote defined in a separate config file, return an
error. Without this, the full configuration would contain duplicate
remote specifications, which would raise an error the next time the repo
is opened.

Closes: #1159
Approved by: cgwalters
This commit is contained in:
Dan Nicholson authored and Atomic Bot committed 2017-09-13 16:03:25 +00:00
1 parent 4cc813133c
commit 3b315e16d8
2 files changed
+62 -1

No files matched your search

+34
View File
@@ -933,6 +933,40 @@ ostree_repo_write_config (OstreeRepo *self,
{
g_return_val_if_fail (self->inited, FALSE);
/* Ensure that any remotes in the new config aren't defined in a
* separate config file.
*/
gsize num_groups;
g_auto(GStrv) groups = g_key_file_get_groups (new_config, &num_groups);
for (gsize i = 0; i < num_groups; i++)
{
g_autoptr(OstreeRemote) new_remote = ostree_remote_new_from_keyfile (new_config, groups[i]);
if (new_remote != NULL)
{
g_autoptr(GError) local_error = NULL;
g_autoptr(OstreeRemote) cur_remote =
_ostree_repo_get_remote (self, new_remote->name, &local_error);
if (cur_remote == NULL)
{
if (!g_error_matches (local_error, G_IO_ERROR,
G_IO_ERROR_NOT_FOUND))
{
g_propagate_error (error, g_steal_pointer (&local_error));
return FALSE;
}
}
else if (cur_remote->file != NULL)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
"Remote \"%s\" already defined in %s",
new_remote->name,
gs_file_get_path_cached (cur_remote->file));
return FALSE;
}
}
}
gsize len;
g_autofree char *data = g_key_file_to_data (new_config, &len, error);
if (!glnx_file_replace_contents_at (self->repo_dir_fd, "config",