Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
190ce16b
Commit
190ce16b
authored
May 09, 2013
by
David Simon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dealing with invalid symlinks and symlink permissions
parent
8ef18c2f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
7 deletions
+23
-7
lib/ansible/module_common.py
+15
-7
test/TestRunner.py
+8
-0
No files found.
lib/ansible/module_common.py
View file @
190ce16b
...
...
@@ -316,7 +316,7 @@ class AnsibleModule(object):
def user_and_group(self, filename):
filename = os.path.expanduser(filename)
st = os.stat(filename)
st = os.
l
stat(filename)
uid = st.st_uid
gid = st.st_gid
return (uid, gid)
...
...
@@ -370,7 +370,7 @@ class AnsibleModule(object):
return True
if orig_uid != uid:
try:
os.chown(path, uid, -1)
os.
l
chown(path, uid, -1)
except OSError:
self.fail_json(path=path, msg='chown failed')
changed = True
...
...
@@ -392,7 +392,7 @@ class AnsibleModule(object):
return True
if orig_gid != gid:
try:
os.chown(path, -1, gid)
os.
l
chown(path, -1, gid)
except OSError:
self.fail_json(path=path, msg='chgrp failed')
changed = True
...
...
@@ -409,7 +409,7 @@ class AnsibleModule(object):
except Exception, e:
self.fail_json(path=path, msg='mode needs to be something octalish', details=str(e))
st = os.stat(path)
st = os.
l
stat(path)
prev_mode = stat.S_IMODE(st[stat.ST_MODE])
if prev_mode != mode:
...
...
@@ -418,11 +418,19 @@ class AnsibleModule(object):
# FIXME: comparison against string above will cause this to be executed
# every time
try:
os.chmod(path, mode)
if 'lchmod' in dir(os):
os.lchmod(path, mode)
else:
os.chmod(path, mode)
except OSError, e:
if e.errno == errno.ENOENT: # Can't set mode on broken symbolic links
pass
else:
raise e
except Exception, e:
self.fail_json(path=path, msg='chmod failed', details=str(e))
st = os.stat(path)
st = os.
l
stat(path)
new_mode = stat.S_IMODE(st[stat.ST_MODE])
if new_mode != prev_mode:
...
...
@@ -483,7 +491,7 @@ class AnsibleModule(object):
group = str(gid)
kwargs['owner'] = user
kwargs['group'] = group
st = os.stat(path)
st = os.
l
stat(path)
kwargs['mode'] = oct(stat.S_IMODE(st[stat.ST_MODE]))
# secontext not yet supported
if os.path.islink(path):
...
...
test/TestRunner.py
View file @
190ce16b
...
...
@@ -230,6 +230,14 @@ class TestRunner(unittest.TestCase):
assert
self
.
_run
(
'file'
,
[
'dest='
+
filedemo
,
'state=absent'
])[
'changed'
]
assert
not
os
.
path
.
exists
(
filedemo
)
assert
not
self
.
_run
(
'file'
,
[
'dest='
+
filedemo
,
'state=absent'
])[
'changed'
]
# Make sure that we can deal safely with bad symlinks
os
.
symlink
(
'/tmp/non_existent_target'
,
filedemo
)
assert
self
.
_run
(
'file'
,
[
'dest='
+
tmp_dir
,
'state=directory recurse=yes mode=701'
])[
'changed'
]
assert
not
self
.
_run
(
'file'
,
[
'dest='
+
tmp_dir
,
'state=directory'
,
'recurse=yes'
,
'owner='
+
str
(
os
.
getuid
())])[
'changed'
]
assert
os
.
path
.
islink
(
filedemo
)
assert
self
.
_run
(
'file'
,
[
'dest='
+
filedemo
,
'state=absent'
])[
'changed'
]
assert
not
os
.
path
.
exists
(
filedemo
)
os
.
rmdir
(
tmp_dir
)
def
test_large_output
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment