From 51b452f0feab577c2d9725eb7331bc90a8d68f97 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 20 Nov 2011 12:38:54 +0100 Subject: [PATCH] Fix creating a solv file when directory does not exist. --- python/src/repo.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/python/src/repo.c b/python/src/repo.c index 652f72ec7..a869d6e0f 100644 --- a/python/src/repo.c +++ b/python/src/repo.c @@ -19,11 +19,13 @@ #############################################################################*/ #include +#include #include #include #include #include +#include "config.h" #include "pool.h" #include "repo.h" #include "solvable.h" @@ -127,6 +129,7 @@ PyObject *Repo_set_priority(RepoObject *self, PyObject *args) { PyObject *Repo_write(RepoObject *self, PyObject *args) { const char *filename; + char exception[STRING_SIZE]; if (!PyArg_ParseTuple(args, "s", &filename)) { /* XXX raise exception */ @@ -136,7 +139,13 @@ PyObject *Repo_write(RepoObject *self, PyObject *args) { _Pool_prepare(self->_repo->pool); // XXX catch if file cannot be opened - FILE *fp = fopen(filename, "wb"); + FILE *fp = NULL; + if ((fp = fopen(filename, "wb")) == NULL) { + snprintf(exception, STRING_SIZE - 1, "Could not open file for writing: %s (%s).", + filename, strerror(errno)); + PyErr_SetString(PyExc_RuntimeError, exception); + return NULL; + } repo_write(self->_repo, fp, NULL, NULL, 0); -- 2.39.5