diff options
author | bescoto <bescoto@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2005-08-11 03:34:03 +0000 |
---|---|---|
committer | bescoto <bescoto@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2005-08-11 03:34:03 +0000 |
commit | ac41194deb402b5611a624be6837e8527a0fd592 (patch) | |
tree | 001f2038d707f397b0afc108165f6ef1aa1ac771 /rdiff-backup/rdiff_backup/cmodule.c | |
parent | 6407faaf13d62710e524009a5174a5948754ed44 (diff) | |
download | rdiff-backup-ac41194deb402b5611a624be6837e8527a0fd592.tar.gz |
Added lchown to cmodule so rdiff-backup can preserve symlink uid/gid
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@606 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/rdiff_backup/cmodule.c')
-rw-r--r-- | rdiff-backup/rdiff_backup/cmodule.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/rdiff-backup/rdiff_backup/cmodule.c b/rdiff-backup/rdiff_backup/cmodule.c index 6fafde7..f6a44a3 100644 --- a/rdiff-backup/rdiff_backup/cmodule.c +++ b/rdiff-backup/rdiff_backup/cmodule.c @@ -368,6 +368,36 @@ static PyObject *acl_unquote(PyObject *self, PyObject *args) return Py_BuildValue("s", unquote(s)); } +/* ------------- lchown taken from Python's posixmodule.c -------------- */ +/* duplicate here to avoid v2.3 requirement */ + +static PyObject * +posix_error_with_allocated_filename(char* name) +{ + PyObject *rc = PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); + PyMem_Free(name); + return rc; +} + +static PyObject * +posix_lchown(PyObject *self, PyObject *args) +{ + char *path = NULL; + int uid, gid; + int res; + if (!PyArg_ParseTuple(args, "etii:lchown", + Py_FileSystemDefaultEncoding, &path, + &uid, &gid)) + return NULL; + Py_BEGIN_ALLOW_THREADS + res = lchown(path, (uid_t) uid, (gid_t) gid); + Py_END_ALLOW_THREADS + if (res < 0) + return posix_error_with_allocated_filename(path); + PyMem_Free(path); + Py_INCREF(Py_None); + return Py_None; +} /* ------------- Python export lists -------------------------------- */ @@ -381,6 +411,8 @@ static PyMethodDef CMethods[] = { "Quote string, escaping non-printables"}, {"acl_unquote", acl_unquote, METH_VARARGS, "Unquote string, producing original input to quote"}, + {"lchown", posix_lchown, METH_VARARGS, + "Like chown, but don't follow symlinks"}, {NULL, NULL, 0, NULL} }; |