stat: Handle colon in filename (#70259)
Handle colon appearing in filename while parsing the mimetype and charset using file command. Fixes: #70256 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
3c9be97e16
commit
29169ae847
3 changed files with 26 additions and 2 deletions
2
changelogs/fragments/70256_stat_colon_split.yml
Normal file
2
changelogs/fragments/70256_stat_colon_split.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- stat - handle colons in filename while parsing the mimetype output (https://github.com/ansible/ansible/issues/70256).
|
|
@ -513,11 +513,11 @@ def main():
|
||||||
output['mimetype'] = output['charset'] = 'unknown'
|
output['mimetype'] = output['charset'] = 'unknown'
|
||||||
mimecmd = module.get_bin_path('file')
|
mimecmd = module.get_bin_path('file')
|
||||||
if mimecmd:
|
if mimecmd:
|
||||||
mimecmd = [mimecmd, '-i', b_path]
|
mimecmd = [mimecmd, '--mime-type', '--mime-encoding', b_path]
|
||||||
try:
|
try:
|
||||||
rc, out, err = module.run_command(mimecmd)
|
rc, out, err = module.run_command(mimecmd)
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
mimetype, charset = out.split(':')[1].split(';')
|
mimetype, charset = out.rsplit(':', 1)[1].split(';')
|
||||||
output['mimetype'] = mimetype.strip()
|
output['mimetype'] = mimetype.strip()
|
||||||
output['charset'] = charset.split('=')[1].strip()
|
output['charset'] = charset.split('=')[1].strip()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
@ -155,3 +155,25 @@
|
||||||
- "'xgrp' in stat_result.stat"
|
- "'xgrp' in stat_result.stat"
|
||||||
- "'xoth' in stat_result.stat"
|
- "'xoth' in stat_result.stat"
|
||||||
- "'xusr' in stat_result.stat"
|
- "'xusr' in stat_result.stat"
|
||||||
|
|
||||||
|
- name: make a new file with colon in filename
|
||||||
|
copy:
|
||||||
|
dest: "{{ output_dir }}/foo:bar.txt"
|
||||||
|
mode: '0644'
|
||||||
|
content: "hello world"
|
||||||
|
|
||||||
|
- name: check stat of a file with colon in name
|
||||||
|
stat:
|
||||||
|
path: "{{ output_dir }}/foo:bar.txt"
|
||||||
|
follow: True
|
||||||
|
register: stat_result
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
var: stat_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "'changed' in stat_result"
|
||||||
|
- "stat_result.changed == false"
|
||||||
|
- "stat_result.stat.mimetype == 'text/plain'"
|
||||||
|
- "stat_result.stat.charset == 'us-ascii'"
|
||||||
|
|
Loading…
Reference in a new issue