summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gluster/swift/obj/diskfile.py14
-rw-r--r--test/unit/obj/test_diskfile.py45
2 files changed, 57 insertions, 2 deletions
diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py
index 2e0837e..f140a62 100644
--- a/gluster/swift/obj/diskfile.py
+++ b/gluster/swift/obj/diskfile.py
@@ -164,7 +164,12 @@ def make_directory(full_path, uid, gid, metadata=None):
# We created it, so we are reponsible for always setting the proper
# ownership.
- do_chown(full_path, uid, gid)
+ if not ((uid == DEFAULT_UID) and (gid == DEFAULT_GID)):
+ # If both UID and GID is -1 (default values), it has no effect.
+ # So don't do a chown.
+ # Further, at the time of this writing, UID and GID information
+ # is not passed to DiskFile.
+ do_chown(full_path, uid, gid)
return True, metadata
@@ -965,7 +970,12 @@ class DiskFile(object):
dw = None
try:
# Ensure it is properly owned before we make it available.
- do_fchown(fd, self._uid, self._gid)
+ if not ((self._uid == DEFAULT_UID) and (self._gid == DEFAULT_GID)):
+ # If both UID and GID is -1 (default values), it has no effect.
+ # So don't do a fchown.
+ # Further, at the time of this writing, UID and GID information
+ # is not passed to DiskFile.
+ do_fchown(fd, self._uid, self._gid)
# NOTE: we do not perform the fallocate() call at all. We ignore
# it completely since at the time of this writing FUSE does not
# support it.
diff --git a/test/unit/obj/test_diskfile.py b/test/unit/obj/test_diskfile.py
index b190526..eab8ebf 100644
--- a/test/unit/obj/test_diskfile.py
+++ b/test/unit/obj/test_diskfile.py
@@ -1097,3 +1097,48 @@ class TestDiskFile(unittest.TestCase):
self.assertFalse(gdf._fd)
# Close the actual fd, as we had mocked do_close
os.close(_m_do_close.call_args[0][0])
+
+ def make_directory_chown_call(self):
+ path = os.path.join(self.td, "a/b/c")
+ _m_do_chown = Mock()
+ with patch("gluster.swift.obj.diskfile.do_chown", _m_do_chown):
+ diskfile.make_directory(path, -1, -1)
+ self.assertFalse(_m_do_chown.called)
+ self.assertTrue(os.path.isdir(path))
+
+ path = os.path.join(self.td, "d/e/f")
+ _m_do_chown.reset_mock()
+ with patch("gluster.swift.obj.diskfile.do_chown", _m_do_chown):
+ diskfile.make_directory(path, -1, 99)
+ self.assertEqual(_m_do_chown.call_count, 3)
+ self.assertTrue(os.path.isdir(path))
+
+ path = os.path.join(self.td, "g/h/i")
+ _m_do_chown.reset_mock()
+ with patch("gluster.swift.obj.diskfile.do_chown", _m_do_chown):
+ diskfile.make_directory(path, 99, -1)
+ self.assertEqual(_m_do_chown.call_count, 3)
+ self.assertTrue(os.path.isdir(path))
+
+ def test_fchown_not_called_on_default_uid_gid_values(self):
+ the_cont = os.path.join(self.td, "vol0", "bar")
+ os.makedirs(the_cont)
+ body = '1234'
+ metadata = {
+ 'X-Timestamp': '1234',
+ 'Content-Type': 'file',
+ 'ETag': md5(body).hexdigest(),
+ 'Content-Length': len(body),
+ }
+
+ _m_do_fchown = Mock()
+ gdf = self._get_diskfile("vol0", "p57", "ufo47", "bar", "z")
+ with gdf.create() as dw:
+ assert dw._tmppath is not None
+ tmppath = dw._tmppath
+ dw.write(body)
+ with patch("gluster.swift.obj.diskfile.do_fchown", _m_do_fchown):
+ dw.put(metadata)
+ self.assertFalse(_m_do_fchown.called)
+ assert os.path.exists(gdf._data_file)
+ assert not os.path.exists(tmppath)