ia64/xen-unstable

changeset 6803:c66a660872e7

Change read and list to return None if key/dir doesn't exist.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Sep 13 14:45:34 2005 +0000 (2005-09-13)
parents 89ed236b6b66
children 68c4eb06a6aa
files tools/python/xen/lowlevel/xs/xs.c
line diff
     1.1 --- a/tools/python/xen/lowlevel/xs/xs.c	Tue Sep 13 10:42:15 2005 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xs/xs.c	Tue Sep 13 14:45:34 2005 +0000
     1.3 @@ -74,6 +74,7 @@ static inline PyObject *pyvalue_str(char
     1.4  	" path [string]: xenstore path\n"	\
     1.5  	"\n"					\
     1.6  	"Returns: [string] data read.\n"	\
     1.7 +	"         None if key doesn't exist.\n"	\
     1.8  	"Raises RuntimeError on error.\n"	\
     1.9  	"\n"
    1.10  
    1.11 @@ -97,7 +98,11 @@ static PyObject *xspy_read(PyObject *sel
    1.12      xsval = xs_read(xh, path, &xsval_n);
    1.13      Py_END_ALLOW_THREADS
    1.14      if (!xsval) {
    1.15 -        PyErr_SetFromErrno(PyExc_RuntimeError);
    1.16 +        if (errno == ENOENT) {
    1.17 +            Py_INCREF(Py_None);
    1.18 +            val = Py_None;
    1.19 +        } else
    1.20 +            PyErr_SetFromErrno(PyExc_RuntimeError);
    1.21          goto exit;
    1.22      }
    1.23      val = PyString_FromStringAndSize(xsval, xsval_n);
    1.24 @@ -160,6 +165,7 @@ static PyObject *xspy_write(PyObject *se
    1.25  	" path [string]: path to list.\n"			\
    1.26  	"\n"							\
    1.27  	"Returns: [string array] list of subdirectory names.\n"	\
    1.28 +	"         None if key doesn't exist.\n"			\
    1.29  	"Raises RuntimeError on error.\n"			\
    1.30  	"\n"
    1.31  
    1.32 @@ -183,12 +189,17 @@ static PyObject *xspy_ls(PyObject *self,
    1.33      xsval = xs_directory(xh, path, &xsval_n);
    1.34      Py_END_ALLOW_THREADS
    1.35      if (!xsval) {
    1.36 -        PyErr_SetFromErrno(PyExc_RuntimeError);
    1.37 -        goto exit;
    1.38 +        if (errno == ENOENT) {
    1.39 +            Py_INCREF(Py_None);
    1.40 +            val = Py_None;
    1.41 +        } else
    1.42 +            PyErr_SetFromErrno(PyExc_RuntimeError);
    1.43 +	goto exit;
    1.44      }
    1.45      val = PyList_New(xsval_n);
    1.46      for (i = 0; i < xsval_n; i++)
    1.47          PyList_SetItem(val, i, PyString_FromString(xsval[i]));
    1.48 +    free(xsval);
    1.49   exit:
    1.50      return val;
    1.51  }