misc: apply umask to created files (#6845)
This commit is contained in:
parent
4e78b42ae5
commit
d478780713
|
@ -9,7 +9,7 @@ import pytest
|
|||
|
||||
from quixote import cleanup
|
||||
from wcs import publisher
|
||||
from wcs.qommon.storage import StorableObject
|
||||
from wcs.qommon.storage import StorableObject, cache_umask
|
||||
import wcs.qommon.storage as st
|
||||
|
||||
from utilities import create_temporary_pub
|
||||
|
@ -40,6 +40,21 @@ def test_store():
|
|||
test.store()
|
||||
assert test.id == 1
|
||||
|
||||
def test_umask():
|
||||
test = Foobar()
|
||||
test.value = 'value'
|
||||
test.unique_value = 'unique-value'
|
||||
|
||||
os.umask(0o022)
|
||||
cache_umask()
|
||||
test.store()
|
||||
assert (os.stat(test.get_object_filename()).st_mode % 0o1000) == 0o644
|
||||
|
||||
os.umask(0o002)
|
||||
cache_umask()
|
||||
test.store()
|
||||
assert (os.stat(test.get_object_filename()).st_mode % 0o1000) == 0o664
|
||||
|
||||
def test_get():
|
||||
test = Foobar.get(1)
|
||||
assert test.value == 'value'
|
||||
|
|
|
@ -374,7 +374,6 @@ def zap_context(msg):
|
|||
'''Removes translation context from message'''
|
||||
return msg.split('|', 1)[1]
|
||||
|
||||
|
||||
def indent_xml(elem, level=0):
|
||||
# in-place prettyprint formatter
|
||||
# http://effbot.org/zone/element-lib.htm#prettyprint
|
||||
|
|
|
@ -30,6 +30,14 @@ except ImportError:
|
|||
|
||||
from quixote import get_publisher
|
||||
|
||||
def cache_umask():
|
||||
global process_umask
|
||||
process_umask = os.umask(0)
|
||||
os.umask(process_umask)
|
||||
|
||||
# cache umask when loading up the module
|
||||
cache_umask()
|
||||
|
||||
def _take(objects, limit, offset=0):
|
||||
for y in objects:
|
||||
if offset:
|
||||
|
@ -61,6 +69,7 @@ def atomic_write(path, content, async=False):
|
|||
dirname = os.path.dirname(path)
|
||||
fd, temp = tempfile.mkstemp(dir=dirname,
|
||||
prefix='.tmp-'+os.path.basename(path)+'-')
|
||||
os.fchmod(fd, 0o666 & ~process_umask)
|
||||
f = os.fdopen(fd, "w")
|
||||
if hasattr(content, 'read'):
|
||||
# file pointer
|
||||
|
|
Loading…
Reference in New Issue