Commit 2d25577e by Brian Coca

Fixes and cleanup to file functions and module

- unified set attribute functions ... not sure why 2 identical functions
exist with diff names, now there are 3 while i repoint all modules to 1
- fixed issue with symlinks being created w/o existing src when force=no
- refactored conditionals, simplified where possible
- added tests for symlink to nonexistant source, with both force options
- made symlink on existing attomic (force)
parent 28dc88ac
......@@ -464,7 +464,7 @@ class AnsibleModule(object):
changed = True
return changed
def set_file_attributes_if_different(self, file_args, changed):
def set_fs_attributes_if_different(self, file_args, changed):
# set modes owners and context as needed
changed = self.set_context_if_different(
file_args['path'], file_args['secontext'], changed
......@@ -481,19 +481,10 @@ class AnsibleModule(object):
return changed
def set_directory_attributes_if_different(self, file_args, changed):
changed = self.set_context_if_different(
file_args['path'], file_args['secontext'], changed
)
changed = self.set_owner_if_different(
file_args['path'], file_args['owner'], changed
)
changed = self.set_group_if_different(
file_args['path'], file_args['group'], changed
)
changed = self.set_mode_if_different(
file_args['path'], file_args['mode'], changed
)
return changed
return self.set_fs_attributes_if_different(file_args, changed)
def set_file_attributes_if_different(self, file_args, changed):
return self.set_fs_attributes_if_different(file_args, changed)
def add_path_info(self, kwargs):
'''
......@@ -963,7 +954,7 @@ class AnsibleModule(object):
context = self.selinux_default_context(dest)
try:
# Optimistically try a rename, solves some corner cases and can avoid useless work.
# Optimistically try a rename, solves some corner cases and can avoid useless work, throws exception if not atomic.
os.rename(src, dest)
except (IOError,OSError), e:
# only try workarounds for errno 18 (cross device), 1 (not permited) and 13 (permission denied)
......
......@@ -164,5 +164,24 @@
that:
- "file11_result.uid == 1235"
- name: fail to create soft link to non existant file
file: src=/noneexistant dest={{output_dir}}/soft2.txt state=link force=no
register: file12_result
ignore_errors: true
- name: verify that link was not created
assert:
that:
- "file12_result.failed == true"
- name: force creation soft link to non existant
file: src=/noneexistant dest={{output_dir}}/soft2.txt state=link force=yes
register: file13_result
- name: verify that link was created
assert:
that:
- "file13_result.changed == true"
- name: remote directory foobar
file: path={{output_dir}}/foobar state=absent
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