pysmb: add py_smb_unlink and test
authorJoe Guo <joeg@catalyst.net.nz>
Tue, 12 Jun 2018 22:39:57 +0000 (10:39 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 28 Jun 2018 07:25:08 +0000 (09:25 +0200)
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>
python/samba/tests/smb.py
source4/libcli/pysmb.c

index 4df83233357004ca13320819f4b6da02577131e7..141e4388e03cfa56dd1ca01a12594e7760c2e0e0 100644 (file)
@@ -53,6 +53,14 @@ class SMBTests(samba.tests.TestCase):
         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'))
index 5bb3807ab76af1b1563d6a6f08b399b7c346392e..a53e30bcf915dd478e8f30f0cbd8e76001708f68 100644 (file)
@@ -258,6 +258,27 @@ static PyObject *py_smb_rmdir(PyObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
        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
  */
 /*
  * 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." },
        { "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." },