mirror of
https://github.com/samba-team/samba.git
synced 2025-08-04 08:22:08 +03:00
s3:pylibsmb: Add .deltree() API to SMB py bindings
This basically re-uses the underlying functionality of existing APIs in order to support a .deltree() API, i.e. - we use the .list() functionality (i.e. do_listing()) to traverse every item in the given directory. - we then use either .unlink() (i.e. unlink_file()) or .rmdir() (i.e. remove_dir()) to delete the individual item. - sub-directories are handled recursively, by repeating the process. Note that the .deltree() API is currently only really used for testing (and deleting GPO files). So the recursion is never going to be excessive. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676 Signed-off-by: Tim Beale <timbeale@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
@ -58,7 +58,7 @@ class SMBTests(samba.tests.TestCase):
|
||||
def tearDown(self):
|
||||
super(SMBTests, self).tearDown()
|
||||
try:
|
||||
self.conn.deltree(test_dir)
|
||||
self.smb_conn.deltree(test_dir)
|
||||
except:
|
||||
pass
|
||||
|
||||
@ -96,6 +96,7 @@ class SMBTests(samba.tests.TestCase):
|
||||
dirpaths = []
|
||||
empty_dirs = []
|
||||
cur_dir = test_dir
|
||||
|
||||
for subdir in ["subdir-X", "subdir-Y", "subdir-Z"]:
|
||||
path = self.make_sysvol_path(cur_dir, subdir)
|
||||
self.smb_conn.mkdir(path)
|
||||
@ -126,18 +127,18 @@ class SMBTests(samba.tests.TestCase):
|
||||
|
||||
# try using deltree to remove a single empty directory
|
||||
path = empty_dirs.pop(0)
|
||||
self.conn.deltree(path)
|
||||
self.smb_conn.deltree(path)
|
||||
self.assertFalse(self.smb_conn.chkpath(path),
|
||||
"Failed to delete {0}".format(path))
|
||||
|
||||
# try using deltree to remove a single file
|
||||
path = filepaths.pop(0)
|
||||
self.conn.deltree(path)
|
||||
self.smb_conn.deltree(path)
|
||||
self.assertFalse(self.file_exists(path),
|
||||
"Failed to delete {0}".format(path))
|
||||
|
||||
# delete the top-level dir
|
||||
self.conn.deltree(test_dir)
|
||||
self.smb_conn.deltree(test_dir)
|
||||
|
||||
# now check that all the dirs/files are no longer there
|
||||
for subdir in dirpaths + empty_dirs:
|
||||
|
Reference in New Issue
Block a user