Commit 2424e64c by Carlos Martín Nieto

config: harden our use of the backend objects a bit

When we create an iterator we don't actually know that we have a live config
object and we must instead only rely on the header. We fixed it to use this in a
previous commit, but this makes it harder to misuse by converting to use the
header object in the typecast.

We also guard inside the `config_refresh` function against being given a
snapshot (although callers right now do check).
parent 1785de4e
......@@ -326,6 +326,9 @@ static int config_refresh(git_config_backend *cfg)
int error, modified;
uint32_t i;
if (b->header.parent.readonly)
return 0;
error = config_is_modified(&modified, &b->file);
if (error < 0 && error != GIT_ENOTFOUND)
goto out;
......@@ -416,13 +419,13 @@ static int config_iterator_new(
diskfile_header *h;
git_config_file_iter *it;
git_config_backend *snapshot;
diskfile_backend *b = (diskfile_backend *) backend;
diskfile_header *bh = (diskfile_header *) backend;
int error;
if ((error = config_snapshot(&snapshot, backend)) < 0)
return error;
if ((error = snapshot->open(snapshot, b->header.level, b->header.repo)) < 0)
if ((error = snapshot->open(snapshot, bh->level, bh->repo)) < 0)
return error;
it = git__calloc(1, sizeof(git_config_file_iter));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment