context: don't raise exception when no partitions found
Allows creation of a context object or device assign if no label is present in the device. This case is not frecuent but not critical, do not raise an exception. For example, a brand new disk with no label or a raw virtual disk image with no label.master
parent
9bf2d030c9
commit
a732758f2b
12
context.c
12
context.c
|
|
@ -74,11 +74,7 @@ static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds)
|
||||||
set_PyErr_from_rc(-rc);
|
set_PyErr_from_rc(-rc);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
fdisk_get_partitions(self->cxt, &self->tb);
|
||||||
if ((fdisk_get_partitions(self->cxt, &self->tb) < 0)) {
|
|
||||||
set_PyErr_from_rc(-rc);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +85,6 @@ static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds)
|
||||||
static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyObject *kwds)
|
static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
char *fname;
|
char *fname;
|
||||||
int rc;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &fname)) {
|
if (!PyArg_ParseTuple(args, "s", &fname)) {
|
||||||
PyErr_SetString(PyExc_TypeError, ARG_ERR);
|
PyErr_SetString(PyExc_TypeError, ARG_ERR);
|
||||||
|
|
@ -102,10 +97,7 @@ static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyOb
|
||||||
fdisk_assign_device(self->cxt, fname, 1);
|
fdisk_assign_device(self->cxt, fname, 1);
|
||||||
|
|
||||||
self->lb = fdisk_get_label(self->cxt, NULL);
|
self->lb = fdisk_get_label(self->cxt, NULL);
|
||||||
if ((rc = fdisk_get_partitions(self->cxt, &self->tb) < 0)) {
|
fdisk_get_partitions(self->cxt, &self->tb);
|
||||||
set_PyErr_from_rc(-rc);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue