From: Michael Tremer Date: Sun, 20 Nov 2011 11:38:54 +0000 (+0100) Subject: Fix creating a solv file when directory does not exist. X-Git-Tag: 0.9.18~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=51b452f0feab577c2d9725eb7331bc90a8d68f97;p=pakfire.git Fix creating a solv file when directory does not exist. --- 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);