return True
return False
-def listdir(fs, dirpath, filter_entries=None):
+def listdir(fs, dirpath, filter_entries=None, filter_files=True):
"""
- Get the directory names (only dirs) for a given path
+ Get the directory entries for a given path. List only dirs if 'filter_files' is True.
+ Don't list the entries passed in 'filter_entries'
"""
- dirs = []
+ entries = []
if filter_entries is None:
filter_entries = [b".", b".."]
else:
with fs.opendir(dirpath) as dir_handle:
d = fs.readdir(dir_handle)
while d:
- if (d.d_name not in filter_entries) and d.is_dir():
- dirs.append(d.d_name)
+ if (d.d_name not in filter_entries):
+ if not filter_files:
+ entries.append(d.d_name)
+ elif d.is_dir():
+ entries.append(d.d_name)
d = fs.readdir(dir_handle)
except cephfs.Error as e:
raise VolumeException(-e.args[0], e.args[1])
- return dirs
+ return entries
def has_subdir(fs, dirpath, filter_entries=None):
from .lock import GlobalLock
from ..exception import VolumeException
from ..fs_util import create_pool, remove_pool, rename_pool, create_filesystem, \
- remove_filesystem, rename_filesystem, create_mds, volume_exists
+ remove_filesystem, rename_filesystem, create_mds, volume_exists, listdir
from .trash import Trash
from mgr_util import open_filesystem, CephfsConnectionException
return result
-def get_pending_subvol_deletions_count(path):
+def get_pending_subvol_deletions_count(fs, path):
"""
Get the number of pending subvolumes deletions.
"""
trashdir = os.path.join(path, Trash.GROUP_NAME)
try:
- num_pending_subvol_del = len(os.listdir(trashdir))
- except OSError as e:
- if e.errno == errno.ENOENT:
+ num_pending_subvol_del = len(listdir(fs, trashdir, filter_entries=None, filter_files=False))
+ except VolumeException as ve:
+ if ve.errno == -errno.ENOENT:
num_pending_subvol_del = 0
return {'pending_subvolume_deletions': num_pending_subvol_del}
cephfs.AT_SYMLINK_NOFOLLOW)
usedbytes = st['size']
- vol_info_dict = get_pending_subvol_deletions_count(path)
+ vol_info_dict = get_pending_subvol_deletions_count(fs_handle, path)
if human_readable:
vol_info_dict['used_size'] = mgr_util.format_bytes(int(usedbytes), 5)
else: