Skip to content

Commit

Permalink
Merge pull request saltstack#9131 from terminalmage/fix-filemanaged-r…
Browse files Browse the repository at this point in the history
…egression

Fix regression in file.managed
  • Loading branch information
thatch45 committed Dec 10, 2013
2 parents 7d9adc6 + 535e6df commit 5c74ec4
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions salt/modules/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,9 +1525,7 @@ def copy(src, dst):
pre_mode = __salt__['config.manage_mode'](get_mode(src))

try:
current_umask = os.umask(63)
shutil.copyfile(src, dst)
os.umask(current_umask)
except OSError:
raise CommandExecutionError(
'Could not copy {0!r} to {1!r}'.format(src, dst)
Expand Down Expand Up @@ -1880,11 +1878,7 @@ def get_managed(
return sfn, source_sum, ''


def check_perms(name,
ret,
user,
group,
mode):
def check_perms(name, ret, user, group, mode):
'''
Check the permissions on files and chown if needed
Expand Down Expand Up @@ -2288,11 +2282,6 @@ def manage_file(name,
ret, 'Failed to commit change, permission error')
__clean_tmp(tmp)

if mode is None:
mask = os.umask(0)
os.umask(mask)
# Apply umask and remove exec bit
mode = (0o0777 ^ mask) & 0o0666
ret, perms = check_perms(name, ret, user, group, mode)

if ret['changes']:
Expand Down Expand Up @@ -2343,7 +2332,7 @@ def manage_file(name,
# Create the file, user rw-only if mode will be set to prevent
# a small security race problem before the permissions are set
if mode:
current_umask = os.umask(63)
current_umask = os.umask(077)

# Create a new file when test is False and source is None
if contents is None:
Expand Down Expand Up @@ -2386,12 +2375,14 @@ def manage_file(name,
__opts__['cachedir'])
__clean_tmp(sfn)

# Check and set the permissions if necessary
# This is a new file, if no mode specified, use the umask to figure
# out what mode to use for the new file.
if mode is None:
# Get current umask
mask = os.umask(0)
os.umask(mask)
# Apply umask and remove exec bit
mode = (0o0777 ^ mask) & 0o0666
# Calculate the mode value that results from the umask
mode = oct((0777 ^ mask) & 0666)
ret, perms = check_perms(name, ret, user, group, mode)

if not ret['comment']:
Expand Down

0 comments on commit 5c74ec4

Please sign in to comment.