Index: /home/tom/projects/workspace/PY-XATTR/trunk/Lib/xattr/__init__.py =================================================================== --- /home/tom/projects/workspace/PY-XATTR/trunk/Lib/xattr/__init__.py (revision 1008) +++ /home/tom/projects/workspace/PY-XATTR/trunk/Lib/xattr/__init__.py (working copy) @@ -69,6 +69,7 @@ See x-man-page://2/getxattr for options and possible errors. """ + # xt.get(namespace.name) | xt.get(name, nmspace=namespace) return self._get(name, 0, 0, options | self.options) def set(self, name, value, options=0): @@ -179,6 +180,7 @@ def getxattr(f, attr, symlink=False): __doc__ = xattr.get.__doc__ + # xattr.getxattr(file, namespace.name) | xattr.getxattr(file, name, nmspace=namespace) return xattr(f).get(attr, options=symlink and XATTR_NOFOLLOW or 0) def setxattr(f, attr, value, options=0, symlink=False): Index: /home/tom/projects/workspace/PY-XATTR/trunk/Modules/xattr/_xattr.c =================================================================== --- /home/tom/projects/workspace/PY-XATTR/trunk/Modules/xattr/_xattr.c (revision 1008) +++ /home/tom/projects/workspace/PY-XATTR/trunk/Modules/xattr/_xattr.c (working copy) @@ -34,6 +34,14 @@ void *value, ssize_t size, u_int32_t position, int options) { + printf("Entering xattr_getxattr!\n"); + int err, len; + ssize_t retval; + int attrnamespace; + char *temp_buffer; + char *nmspace; + char *nm; + if (position != 0 || !(options == 0 || options == XATTR_XATTR_NOFOLLOW)) { return -1; @@ -39,14 +47,42 @@ return -1; } + len = strlen(name)+1; + temp_buffer = (char *) malloc(len); + nm = temp_buffer; + strlcpy(nm, name, len); + printf("path: %s\n", path); + printf("name: %s\n", name); + printf("nm: %s\n", nm); + + nmspace = strsep(&nm, "."); + + printf("nmspace: %s\n", nmspace); + printf("nm (after strsep()): %s\n", nm); + + // Why does the error change the second time around? + if (nm == NULL || *nm == 0) { + printf("nm is NULL or empty\n"); + free(temp_buffer); + return -2; + } + + err = extattr_string_to_namespace(nmspace, &attrnamespace); + if (err) { + free(temp_buffer); + return -1; + } + if (options & XATTR_XATTR_NOFOLLOW) { - return extattr_get_link(path, EXTATTR_NAMESPACE_USER, - name, value, size); + retval = extattr_get_link(path, attrnamespace, nm, value, size); } else { - return extattr_get_file(path, EXTATTR_NAMESPACE_USER, - name, value, size); + retval = extattr_get_file(path, attrnamespace, nm, value, size); } + + free(temp_buffer); + + return retval; } static ssize_t xattr_setxattr(const char *path, const char *name, @@ -359,6 +395,7 @@ static PyObject * xattr_error(void) { + printf("entered xattr_error\n"); return PyErr_SetFromErrno(PyExc_IOError); } @@ -365,6 +402,7 @@ static PyObject * xattr_error_with_filename(char *name) { + printf("entered xattr_error_with_filename\n"); return PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); } @@ -403,6 +441,12 @@ PyMem_Free(name); return tmp; } + else if (res == -2) { + PyObject *tmp = xattr_error(); + PyMem_Free(path); + PyMem_Free(name); + return tmp; + } size = res; } buffer = PyString_FromStringAndSize((char *)NULL, size); @@ -421,6 +465,13 @@ PyMem_Free(name); return tmp; } + else if (res == -2 ) { + PyObject *tmp = xattr_error(); + Py_DECREF(buffer); + PyMem_Free(path); + PyMem_Free(name); + return tmp; + } PyMem_Free(path); PyMem_Free(name); if (res != size) {