Add unlink api to delete a file with a smb connection.
Test added.
Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
self.assertIn('Policies',ls,
msg='"Policies" directory not found in sysvol')
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'))
def test_save_load_text(self):
self.conn.savefile(test_file, test_contents.encode('utf8'))
+
+/*
+ * 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
*/
/*
* Remove a directory and all its contents
*/
{ "rmdir", py_smb_rmdir, METH_VARARGS,
"rmdir(path) -> None\n\n \
Delete a directory." },
{ "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." },
{ "deltree", py_smb_deltree, METH_VARARGS,
"deltree(path) -> None\n\n \
Delete a directory and all its contents." },