diff options
-rw-r--r-- | python/samba/tests/smb.py | 8 | ||||
-rw-r--r-- | source4/libcli/pysmb.c | 24 |
2 files changed, 32 insertions, 0 deletions
diff --git a/python/samba/tests/smb.py b/python/samba/tests/smb.py index 4df83233357..141e4388e03 100644 --- a/python/samba/tests/smb.py +++ b/python/samba/tests/smb.py @@ -53,6 +53,14 @@ class SMBTests(samba.tests.TestCase): self.assertIn('Policies',ls, msg='"Policies" directory not found in sysvol') + def test_unlink(self): + """ + The smb.unlink API should delete file + """ + self.conn.savefile(test_file, binary_contents); + self.conn.unlink(test_file) + self.assertFalse(self.conn.chkpath(test_file)) + def test_save_load_text(self): self.conn.savefile(test_file, test_contents.encode('utf8')) diff --git a/source4/libcli/pysmb.c b/source4/libcli/pysmb.c index 5bb3807ab76..a53e30bcf91 100644 --- a/source4/libcli/pysmb.c +++ b/source4/libcli/pysmb.c @@ -258,6 +258,27 @@ static PyObject *py_smb_rmdir(PyObject *self, PyObject *args) Py_RETURN_NONE; } + +/* + * Remove a file + */ +static PyObject *py_smb_unlink(PyObject *self, PyObject *args) +{ + NTSTATUS status; + const char *filename; + struct smb_private_data *spdata; + + if (!PyArg_ParseTuple(args, "s:unlink", &filename)) { + return NULL; + } + + spdata = pytalloc_get_ptr(self); + status = smbcli_unlink(spdata->tree, filename); + PyErr_NTSTATUS_IS_ERR_RAISE(status); + + Py_RETURN_NONE; +} + /* * Remove a directory and all its contents */ @@ -551,6 +572,9 @@ FILE_ATTRIBUTE_ARCHIVE\n\n \ { "rmdir", py_smb_rmdir, METH_VARARGS, "rmdir(path) -> None\n\n \ Delete a directory." }, + { "unlink", py_smb_unlink, METH_VARARGS, + "unlink(path) -> None\n\n \ + Delete a file." }, { "deltree", py_smb_deltree, METH_VARARGS, "deltree(path) -> None\n\n \ Delete a directory and all its contents." }, |