summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gluster/swift/common/DiskDir.py14
-rw-r--r--gluster/swift/common/utils.py26
-rw-r--r--test/unit/common/test_diskdir.py3
-rw-r--r--test/unit/common/test_utils.py10
4 files changed, 31 insertions, 22 deletions
diff --git a/gluster/swift/common/DiskDir.py b/gluster/swift/common/DiskDir.py
index 204ae1d..4f4a2ef 100644
--- a/gluster/swift/common/DiskDir.py
+++ b/gluster/swift/common/DiskDir.py
@@ -14,6 +14,7 @@
# limitations under the License.
import os
+import stat
import errno
from gluster.swift.common.fs_utils import dir_empty, mkdirs, do_chown, \
@@ -177,7 +178,7 @@ class DiskCommon(object):
self.logger = logger
self.account = account
self.datadir = os.path.join(root, drive)
- self._dir_exists = None
+ self._dir_exists = False
# nthread=0 is intentional. This ensures that no green pool is
# used. Call to force_run_in_thread() will ensure that the method
@@ -186,7 +187,7 @@ class DiskCommon(object):
self.threadpool = ThreadPool(nthreads=0)
def _dir_exists_read_metadata(self):
- self._dir_exists = do_exists(self.datadir)
+ self._dir_exists = os.path.isdir(self.datadir)
if self._dir_exists:
try:
self.metadata = _read_metadata(self.datadir)
@@ -199,7 +200,7 @@ class DiskCommon(object):
def is_deleted(self):
# The intention of this method is to check the file system to see if
# the directory actually exists.
- return not do_exists(self.datadir)
+ return not self._dir_exists
def empty(self):
# If it does not exist, then it is empty. A value of True is
@@ -356,6 +357,8 @@ class DiskDir(DiskCommon):
# object count and bytes used. Return immediately before metadata
# validation and creation happens.
info = do_stat(self.datadir)
+ if info and stat.S_ISDIR(info.st_mode):
+ self._dir_exists = True
if not info:
# Container no longer exists.
return
@@ -526,7 +529,7 @@ class DiskDir(DiskCommon):
return objects
def get_info_is_deleted(self):
- if not do_exists(self.datadir):
+ if not self._dir_exists:
return {}, True
info = self.get_info()
return info, False
@@ -622,6 +625,7 @@ class DiskDir(DiskCommon):
# where created by the code, but not by the
# caller as objects
rmobjdir(self.datadir)
+ self._dir_exists = False
def set_x_container_sync_points(self, sync_point1, sync_point2):
self.metadata['x_container_sync_point1'] = sync_point1
@@ -679,6 +683,8 @@ class DiskAccount(DiskCommon):
# used. Return immediately before metadata validation and
# creation happens.
info = do_stat(self.datadir)
+ if info and stat.S_ISDIR(info.st_mode):
+ self._dir_exists = True
semi_fake_md = {
'X-Object-Count': (0, 0),
'X-Container-Count': (0, 0),
diff --git a/gluster/swift/common/utils.py b/gluster/swift/common/utils.py
index a27aaf0..8f68319 100644
--- a/gluster/swift/common/utils.py
+++ b/gluster/swift/common/utils.py
@@ -28,9 +28,9 @@ from gluster.swift.common.exceptions import GlusterFileSystemIOError
from swift.common.exceptions import DiskFileNoSpace
from swift.common.db import utf8encodekeys
from gluster.swift.common.fs_utils import do_getctime, do_getmtime, do_stat, \
- do_rmdir, do_log_rl, get_filename_from_fd, do_open, \
- do_isdir, do_getsize, do_getxattr, do_setxattr, do_removexattr, do_read, \
- do_close, do_dup, do_lseek, do_fstat, do_fsync, do_rename
+ do_rmdir, do_log_rl, get_filename_from_fd, do_open, do_getsize, \
+ do_getxattr, do_setxattr, do_removexattr, do_read, do_close, do_dup, \
+ do_lseek, do_fstat, do_fsync, do_rename
from gluster.swift.common import Glusterfs
try:
@@ -371,13 +371,12 @@ def get_container_details(cont_path):
object_count = 0
obj_list = []
- if do_isdir(cont_path):
- for (path, dirs, files) in gf_walk(cont_path):
- object_count, bytes_used = update_list(path, cont_path, dirs,
- files, object_count,
- bytes_used, obj_list)
+ for (path, dirs, files) in gf_walk(cont_path):
+ object_count, bytes_used = update_list(path, cont_path, dirs,
+ files, object_count,
+ bytes_used, obj_list)
- sleep()
+ sleep()
return obj_list, object_count, bytes_used
@@ -445,11 +444,10 @@ def get_account_details(acc_path):
"""
container_list = []
- if os.path.isdir(acc_path):
- for entry in gf_listdir(acc_path):
- if entry.is_dir() and \
- entry.name not in (TEMP_DIR, ASYNCDIR, TRASHCAN):
- container_list.append(entry.name)
+ for entry in gf_listdir(acc_path):
+ if entry.is_dir() and \
+ entry.name not in (TEMP_DIR, ASYNCDIR, TRASHCAN):
+ container_list.append(entry.name)
return container_list, len(container_list)
diff --git a/test/unit/common/test_diskdir.py b/test/unit/common/test_diskdir.py
index 964bc2f..ae9aa6e 100644
--- a/test/unit/common/test_diskdir.py
+++ b/test/unit/common/test_diskdir.py
@@ -279,7 +279,7 @@ class TestDiskCommon(unittest.TestCase):
assert dc.logger == self.fake_logger
assert dc.account == self.fake_accounts[0]
assert dc.datadir == os.path.join(self.td, self.fake_drives[0])
- assert dc._dir_exists is None
+ assert dc._dir_exists is False
def test__dir_exists_read_metadata_exists(self):
datadir = os.path.join(self.td, self.fake_drives[0])
@@ -315,6 +315,7 @@ class TestDiskCommon(unittest.TestCase):
def test_is_deleted(self):
dc = dd.DiskCommon(self.td, self.fake_drives[0],
self.fake_accounts[0], self.fake_logger)
+ dc._dir_exists_read_metadata()
assert dc.is_deleted() == False
def test_update_metadata(self):
diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py
index 4790304..136c3a9 100644
--- a/test/unit/common/test_utils.py
+++ b/test/unit/common/test_utils.py
@@ -670,9 +670,13 @@ class TestUtils(unittest.TestCase):
def test_get_account_details_notadir(self):
tf = tempfile.NamedTemporaryFile()
- container_list, container_count = utils.get_account_details(tf.name)
- assert container_count == 0
- assert container_list == []
+ try:
+ utils.get_account_details(tf.name)
+ except OSError as err:
+ if err.errno != errno.ENOTDIR:
+ self.fail("Expecting ENOTDIR")
+ else:
+ self.fail("Expecting ENOTDIR")
def test_get_container_details_notadir(self):
tf = tempfile.NamedTemporaryFile()