# Configure which filesystem to mount if one was specified
if filesystem_name is None:
filesystem_name = b""
+ else:
+ filesystem_name = cstr(filesystem_name, 'filesystem_name')
cdef:
char *_filesystem_name = filesystem_name
if filesystem_name:
logger.warning("[NFS] Limiting depth to maximum value of 5: "
"input depth=%s", depth)
depth = 5
- root_dir = '{}/'.format(root_dir) \
- if not root_dir.endswith('/') else root_dir
-
+ root_dir = '{}{}'.format(root_dir.rstrip('/'), '/')
try:
cfs = CephFS()
+ root_dir = root_dir.encode()
paths = cfs.get_dir_list(root_dir, depth)
- paths = [p[:-1] for p in paths if p != root_dir]
- return {'paths': paths}
+ # Convert (bytes => string) and prettify paths (strip slashes).
+ paths = [p.decode().rstrip('/') for p in paths if p != root_dir]
except (cephfs.ObjectNotFound, cephfs.PermissionError):
- return {'paths': []}
+ paths = []
+ return {'paths': paths}
@Endpoint('GET', '/cephfs/filesystems')
def filesystems(self):
from contextlib import contextmanager
+import six
import cephfs
from .. import mgr, logger
self.cfs.closedir(d)
def get_dir_list(self, dirpath, level):
+ """
+ :param dirpath: The root directory path.
+ :type dirpath: str | bytes
+ :param level: The number of steps to go down the directory tree.
+ :type level: int
+ :return: A list of directory paths (bytes encoded).
+ :rtype: list
+ """
+ if isinstance(dirpath, six.string_types):
+ dirpath = dirpath.encode()
logger.debug("[CephFS] get_dir_list dirpath=%s level=%s", dirpath,
level)
if level == 0:
paths = [dirpath]
while dent:
logger.debug("[CephFS] found entry=%s", dent.d_name)
- if dent.d_name in ['.', '..']:
+ if dent.d_name in [b'.', b'..']:
dent = self.cfs.readdir(d)
continue
if dent.is_dir():
logger.debug("[CephFS] found dir=%s", dent.d_name)
- subdirpath = '{}{}/'.format(dirpath, dent.d_name)
+ subdirpath = b''.join([dirpath, dent.d_name, b'/'])
paths.extend(self.get_dir_list(subdirpath, level-1))
dent = self.cfs.readdir(d)
return paths