Skip to content

Commit 0bd6cf9

Browse files
committed
implement unlink()
1 parent fabe938 commit 0bd6cf9

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

commands.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,27 @@ int python_rename(vfs_handle_struct *handle,
159159
return -1;
160160
}
161161
}
162+
163+
int python_unlink(vfs_handle_struct *handle,
164+
const struct smb_filename *smb_fname)
165+
{
166+
int success = 1;
167+
168+
PyObject *py_func = get_func(handle, "unlink");
169+
if (py_func != NULL)
170+
{
171+
PyObject *py_ret = PyObject_CallFunction(py_func, "s", smb_fname->base_name);
172+
success = PyObject_IsTrue(py_ret);
173+
Py_DECREF(py_ret);
174+
Py_DECREF(py_func);
175+
}
176+
177+
if (success == 1)
178+
{
179+
return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
180+
}
181+
else
182+
{
183+
return -1;
184+
}
185+
}

commands.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ NTSTATUS python_create_file(struct vfs_handle_struct *handle,
2929
int python_rename(vfs_handle_struct *handle,
3030
const struct smb_filename *smb_fname_src,
3131
const struct smb_filename *smb_fname_dst);
32+
int python_unlink(vfs_handle_struct *handle,
33+
const struct smb_filename *smb_fname);

handler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ def rename(source, target):
2727
if target == 'bad_file':
2828
return False
2929
return True
30+
31+
def unlink(path):
32+
debug('Unlink: {}'.format(path))
33+
if path == 'mc_hammer':
34+
return False
35+
return True

vfs_python.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ static struct vfs_fn_pointers vfs_python_fns = {
77
.mkdir_fn = python_mkdir,
88
.rmdir_fn = python_rmdir,
99
.create_file_fn = python_create_file,
10-
.rename_fn = python_rename
10+
.rename_fn = python_rename,
11+
.unlink_fn = python_unlink
1112
};
1213

1314
#define vfs_python_init samba_init_module

0 commit comments

Comments
 (0)