[util] Remove umask manipulation from makedirs
This causes a race condition: umask is process-wide setting, so any file created by another thread while the umask is set to 0 will have wrong permissions. This also removes the possible problem of not resetting the umask if exception is raised. Fixes: #239 Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
4ec8ad5de8
commit
69316d827a
@ -138,13 +138,11 @@ def _doCheckSum(path, hash, logger):
|
|||||||
|
|
||||||
|
|
||||||
def makedirs(path, mode=0o775):
|
def makedirs(path, mode=0o775):
|
||||||
mask = os.umask(0)
|
|
||||||
try:
|
try:
|
||||||
os.makedirs(path, mode=mode)
|
os.makedirs(path, mode=mode)
|
||||||
except OSError as ex:
|
except OSError as ex:
|
||||||
if ex.errno != errno.EEXIST:
|
if ex.errno != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
os.umask(mask)
|
|
||||||
|
|
||||||
|
|
||||||
def rmtree(path, ignore_errors=False, onerror=None):
|
def rmtree(path, ignore_errors=False, onerror=None):
|
||||||
|
@ -13,7 +13,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|||||||
from pungi import compose
|
from pungi import compose
|
||||||
from pungi import util
|
from pungi import util
|
||||||
|
|
||||||
from tests.helpers import touch
|
from tests.helpers import touch, PungiTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestGitRefResolver(unittest.TestCase):
|
class TestGitRefResolver(unittest.TestCase):
|
||||||
@ -193,7 +193,7 @@ class TestFindOldCompose(unittest.TestCase):
|
|||||||
self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-Base-1-20160229.0')
|
self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-Base-1-20160229.0')
|
||||||
|
|
||||||
|
|
||||||
class TestHelpers(unittest.TestCase):
|
class TestHelpers(PungiTestCase):
|
||||||
def test_process_args(self):
|
def test_process_args(self):
|
||||||
self.assertEqual(util.process_args('--opt={}', None), [])
|
self.assertEqual(util.process_args('--opt={}', None), [])
|
||||||
self.assertEqual(util.process_args('--opt={}', []), [])
|
self.assertEqual(util.process_args('--opt={}', []), [])
|
||||||
@ -201,6 +201,17 @@ class TestHelpers(unittest.TestCase):
|
|||||||
['--opt=foo', '--opt=bar'])
|
['--opt=foo', '--opt=bar'])
|
||||||
self.assertEqual(util.process_args('--opt={}', 'foo'), ['--opt=foo'])
|
self.assertEqual(util.process_args('--opt={}', 'foo'), ['--opt=foo'])
|
||||||
|
|
||||||
|
def test_makedirs(self):
|
||||||
|
util.makedirs(self.topdir + '/foo/bar/baz')
|
||||||
|
self.assertTrue(os.path.isdir(self.topdir + '/foo/bar/baz'))
|
||||||
|
|
||||||
|
def test_makedirs_on_existing(self):
|
||||||
|
os.makedirs(self.topdir + '/foo/bar/baz')
|
||||||
|
try:
|
||||||
|
util.makedirs(self.topdir + '/foo/bar/baz')
|
||||||
|
except OSError:
|
||||||
|
self.fail('makedirs raised exception on existing directory')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user