Commit b73360e3 authored by Balazs Lecz's avatar Balazs Lecz
Browse files

Make utils.EnsureDirs() ignore umask



EnsureDirs() should create directories with the exact mode requested
in the arguments, but it currently applies the umask.
This patch makes it independent from the umask.
Signed-off-by: default avatarBalazs Lecz <leczb@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent e0561198
......@@ -1388,6 +1388,11 @@ def EnsureDirs(dirs):
if err.errno != errno.EEXIST:
raise errors.GenericError("Cannot create needed directory"
" '%s': %s" % (dir_name, err))
try:
os.chmod(dir_name, dir_mode)
except EnvironmentError, err:
raise errors.GenericError("Cannot change directory permissions on"
" '%s': %s" % (dir_name, err))
if not os.path.isdir(dir_name):
raise errors.GenericError("%s is not a directory" % dir_name)
......
......@@ -1859,5 +1859,26 @@ class TestIgnoreSignals(unittest.TestCase):
self.assertEquals(utils.IgnoreSignals(self._Return, 33), 33)
class TestEnsureDirs(unittest.TestCase):
"""Tests for EnsureDirs"""
def setUp(self):
self.dir = tempfile.mkdtemp()
self.old_umask = os.umask(0777)
def testEnsureDirs(self):
utils.EnsureDirs([
(utils.PathJoin(self.dir, "foo"), 0777),
(utils.PathJoin(self.dir, "bar"), 0000),
])
self.assertEquals(os.stat(utils.PathJoin(self.dir, "foo"))[0] & 0777, 0777)
self.assertEquals(os.stat(utils.PathJoin(self.dir, "bar"))[0] & 0777, 0000)
def tearDown(self):
os.rmdir(utils.PathJoin(self.dir, "foo"))
os.rmdir(utils.PathJoin(self.dir, "bar"))
os.rmdir(self.dir)
os.umask(self.old_umask)
if __name__ == '__main__':
testutils.GanetiTestProgram()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment