From 70c5345042dd2966f40d84e80592ffa9fd3025d9 Mon Sep 17 00:00:00 2001 From: nchilaka Date: Wed, 20 May 2020 22:41:42 +0530 Subject: [Libfix] Fetch all entries under a directory in recursive fashion This method fetches all entries under a directory in recursive fashion Change-Id: I4fc066ccf7a3a4730d568f96d926e46dea7b20a1 Signed-off-by: nchilaka --- glustolibs-gluster/glustolibs/gluster/glusterdir.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'glustolibs-gluster/glustolibs/gluster/glusterdir.py') diff --git a/glustolibs-gluster/glustolibs/gluster/glusterdir.py b/glustolibs-gluster/glustolibs/gluster/glusterdir.py index f2981cb93..5618926c8 100644 --- a/glustolibs-gluster/glustolibs/gluster/glusterdir.py +++ b/glustolibs-gluster/glustolibs/gluster/glusterdir.py @@ -82,22 +82,29 @@ def rmdir(host, fqpath, force=False): return False -def get_dir_contents(host, path): +def get_dir_contents(host, path, recursive=False): """Get the files and directories present in a given directory. Args: host (str): The hostname/ip of the remote system. path (str): The path to the directory. + Kwargs: + recursive (bool): lists all entries recursively + Returns: file_dir_list (list): List of files and directories on path. None: In case of error or failure. """ - ret, out, _ = g.run(host, ' ls '+path) - if ret != 0: + if recursive: + cmd = "find {}".format(path) + else: + cmd = "ls " + path + ret, out, _ = g.run(host, cmd) + if ret: + g.log.error("No such file or directory {}".format(path)) return None - file_dir_list = list(filter(None, out.split("\n"))) - return file_dir_list + return(list(filter(None, out.split("\n")))) class GlusterDir(GlusterFile): -- cgit