Merge pull request #8441 from willthames/unarchive_dest_fix

Unarchive should work when parent directory is not writable
pull/5123/merge
Michael DeHaan 10 years ago
commit 3871eebfbb

@ -115,8 +115,6 @@ class TgzFile(object):
self.zipflag = 'z' self.zipflag = 'z'
def is_unarchived(self): def is_unarchived(self):
dirof = os.path.dirname(self.dest)
destbase = os.path.basename(self.dest)
cmd = '%s -v -C "%s" --diff -%sf "%s"' % (self.cmd_path, self.dest, self.zipflag, self.src) cmd = '%s -v -C "%s" --diff -%sf "%s"' % (self.cmd_path, self.dest, self.zipflag, self.src)
rc, out, err = self.module.run_command(cmd) rc, out, err = self.module.run_command(cmd)
unarchived = (rc == 0) unarchived = (rc == 0)
@ -220,10 +218,10 @@ def main():
) )
# is dest OK to receive tar file? # is dest OK to receive tar file?
if not os.path.exists(os.path.dirname(dest)): if not os.path.isdir(dest):
module.fail_json(msg="Destination directory '%s' does not exist" % (os.path.dirname(dest))) module.fail_json(msg="Destination '%s' is not a directory" % dest)
if not os.access(os.path.dirname(dest), os.W_OK): if not os.access(dest, os.W_OK):
module.fail_json(msg="Destination '%s' not writable" % (os.path.dirname(dest))) module.fail_json(msg="Destination '%s' not writable" % dest)
handler = pick_handler(src, dest, module) handler = pick_handler(src, dest, module)

@ -111,3 +111,27 @@
- name: remove our test file for the archive - name: remove our test file for the archive
file: path={{output_dir}}/foo-unarchive.txt state=absent file: path={{output_dir}}/foo-unarchive.txt state=absent
- name: check if /tmp/foo-unarchive.text exists
stat: path=/tmp/foo-unarchive.txt
ignore_errors: True
register: unarchive04
- name: fail if the proposed destination file exists for safey
fail: msg="/tmp/foo-unarchive.txt already exists, aborting"
when: unarchive04.stat.exists
- name: try unarchiving to /tmp
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest=/tmp copy=no
register: unarchive05
- name: verify that the file was marked as changed
assert:
that:
- "unarchive05.changed == true"
- name: verify that the file was unarchived
file: path=/tmp/foo-unarchive.txt state=file
- name: remove our unarchive destination
file: path=/tmp/foo-unarchive.txt state=absent

Loading…
Cancel
Save