mirror of
https://github.com/samba-team/samba.git
synced 2025-01-26 10:04:02 +03:00
pysmb: add py_smb_unlink and test
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>
This commit is contained in:
parent
211275fae6
commit
4320dcc4bc
@ -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'))
|
||||
|
@ -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." },
|
||||
|
Loading…
x
Reference in New Issue
Block a user