From 1f2228855937ffea9ae0d66ad78cdab8357fcaa1 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Wed, 10 Jul 2019 16:08:29 -0700 Subject: [PATCH] pybind/mgr/subvolumes: use bytes for paths Signed-off-by: Patrick Donnelly (cherry picked from commit 3d63cd947f55a8508f972ee249ea6a04836429ae) --- src/pybind/mgr/volumes/fs/subvolspec.py | 10 +++++----- src/pybind/mgr/volumes/fs/subvolume.py | 14 +++++--------- src/pybind/mgr/volumes/fs/volume.py | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/pybind/mgr/volumes/fs/subvolspec.py b/src/pybind/mgr/volumes/fs/subvolspec.py index ca3740a51a39c..60fb6d06af009 100644 --- a/src/pybind/mgr/volumes/fs/subvolspec.py +++ b/src/pybind/mgr/volumes/fs/subvolspec.py @@ -49,28 +49,28 @@ class SubvolumeSpec(object): """ return the subvolume path from subvolume specification """ - return os.path.join(self.subvolume_prefix, self.groupid, self.subvolumeid) + return os.path.join(self.group_path, self.subvolumeid.encode('utf-8')) @property def group_path(self): """ return the group path from subvolume specification """ - return os.path.join(self.subvolume_prefix, self.groupid) + return os.path.join(self.subvolume_prefix.encode('utf-8'), self.groupid.encode('utf-8')) @property def trash_path(self): """ return the trash path from subvolume specification """ - return os.path.join(self.subvolume_prefix, "_deleting", self.subvolumeid) + return os.path.join(self.subvolume_prefix.encode('utf-8'), b"_deleting", self.subvolumeid.encode('utf-8')) @property def unique_trash_path(self): """ return a unique trash directory entry path """ - return os.path.join(self.subvolume_prefix, "_deleting", str(uuid.uuid4())) + return os.path.join(self.subvolume_prefix.encode('utf-8'), b"_deleting", str(uuid.uuid4()).encode('utf-8')) @property def fs_namespace(self): @@ -84,7 +84,7 @@ class SubvolumeSpec(object): """ return the trash directory path """ - return os.path.join(self.subvolume_prefix, "_deleting") + return os.path.join(self.subvolume_prefix.encode('utf-8'), b"_deleting") def make_subvol_snap_path(self, snapdir, snapname): """ diff --git a/src/pybind/mgr/volumes/fs/subvolume.py b/src/pybind/mgr/volumes/fs/subvolume.py index 6abbc581c8a83..d88336254ac79 100644 --- a/src/pybind/mgr/volumes/fs/subvolume.py +++ b/src/pybind/mgr/volumes/fs/subvolume.py @@ -66,13 +66,13 @@ class SubVolume(object): except cephfs.Error as e: raise VolumeException(-e.args[0], e.args[1]) - exclude.extend([".", ".."]) + exclude.extend((b".", b"..")) d = self.fs.readdir(dir_handle) d_name = None while d: - if not d.d_name.decode('utf-8') in exclude and d.is_dir(): - d_name = d.d_name.decode('utf-8') + if not d.d_name in exclude and d.is_dir(): + d_name = d.d_name break d = self.fs.readdir(dir_handle) self.fs.closedir(dir_handle) @@ -164,12 +164,8 @@ class SubVolume(object): raise VolumeException(-e.args[0], e.args[1]) d = self.fs.readdir(dir_handle) while d and not should_cancel(): - d_name = d.d_name.decode('utf-8') - if d_name not in [".", ".."]: - # Do not use os.path.join because it is sensitive - # to string encoding, we just pass through dnames - # as byte arrays - d_full = "{0}/{1}".format(root_path, d_name) + if d.d_name not in (b".", b".."): + d_full = os.path.join(root_path, d.d_name) if d.is_dir(): rmtree(d_full) else: diff --git a/src/pybind/mgr/volumes/fs/volume.py b/src/pybind/mgr/volumes/fs/volume.py index b2d72d7d06bf1..d3fe6d99a41fe 100644 --- a/src/pybind/mgr/volumes/fs/volume.py +++ b/src/pybind/mgr/volumes/fs/volume.py @@ -582,7 +582,7 @@ class VolumeClient(object): try: with SubVolume(self.mgr, fs_handle) as sv: - spec = SubvolumeSpec(purge_dir, "") + spec = SubvolumeSpec(purge_dir.decode('utf-8'), "") sv.purge_subvolume(spec, should_cancel) except VolumeException as ve: ret = self.volume_exception_to_retval(ve) -- 2.39.5