diff options
author | nchilaka <nchilaka@redhat.com> | 2020-05-20 22:41:42 +0530 |
---|---|---|
committer | Bala Konda Reddy M <bala12352@gmail.com> | 2020-05-22 05:40:43 +0000 |
commit | 70c5345042dd2966f40d84e80592ffa9fd3025d9 (patch) | |
tree | e1d63cb1a0b3ef8984522d2f0b05774f7398001a /glustolibs-gluster/glustolibs | |
parent | dee6e2b55f604a9c1a41ea80152487d6317a905b (diff) |
[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 <nchilaka@redhat.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs')
-rw-r--r-- | glustolibs-gluster/glustolibs/gluster/glusterdir.py | 17 |
1 files changed, 12 insertions, 5 deletions
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): |