mirror of
https://github.com/ansible/ansible.git
synced 2026-08-03 08:03:05 +02:00
copy keep suffix on temp file for validation (#82158)
Also updated test to require suffix Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com>
This commit is contained in:
co-authored by
Sloane Hertel
parent
a8b6ef7e7c
commit
4a84a9b3db
@@ -0,0 +1,4 @@
|
||||
bugfixes:
|
||||
- copy action now ensures that tempfiles use the same suffix as destination, to allow for ``validate`` to work with utilities that check extensions.
|
||||
- copy action now also generates temprary files as hidden ('.' prefixed) to avoid accidental pickup by running services that glob by extension.
|
||||
- template action will also inherit the behavior from copy (as it uses it internally).
|
||||
@@ -292,7 +292,12 @@ class ActionModule(ActionBase):
|
||||
return result
|
||||
|
||||
# Define a remote directory that we will copy the file to.
|
||||
tmp_src = self._connection._shell.join_path(self._connection._shell.tmpdir, 'source')
|
||||
tmp_src = self._connection._shell.join_path(self._connection._shell.tmpdir, '.source')
|
||||
|
||||
# ensure we keep suffix for validate
|
||||
suffix = os.path.splitext(dest_file)[1]
|
||||
if suffix:
|
||||
tmp_src += suffix
|
||||
|
||||
remote_path = None
|
||||
|
||||
@@ -385,7 +390,7 @@ class ActionModule(ActionBase):
|
||||
|
||||
def _create_content_tempfile(self, content):
|
||||
''' Create a tempfile containing defined content '''
|
||||
fd, content_tempfile = tempfile.mkstemp(dir=C.DEFAULT_LOCAL_TMP)
|
||||
fd, content_tempfile = tempfile.mkstemp(dir=C.DEFAULT_LOCAL_TMP, prefix='.')
|
||||
f = os.fdopen(fd, 'wb')
|
||||
content = to_bytes(content)
|
||||
try:
|
||||
|
||||
+1
-1
@@ -166,7 +166,7 @@ changed: [testhost] =>
|
||||
mode: '0644'
|
||||
owner: root
|
||||
size: 3
|
||||
src: .../source
|
||||
src: .../.source.txt
|
||||
state: file
|
||||
uid: 0
|
||||
|
||||
|
||||
+1
-1
@@ -173,7 +173,7 @@ changed: [testhost] =>
|
||||
mode: '0644'
|
||||
owner: root
|
||||
size: 3
|
||||
src: .../source
|
||||
src: .../.source.txt
|
||||
state: file
|
||||
uid: 0
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ run_test() {
|
||||
sed -i -e 's/^Using .*//g' "${OUTFILE}.${testname}.stdout"
|
||||
sed -i -e 's/[0-9]:[0-9]\{2\}:[0-9]\{2\}\.[0-9]\{6\}/0:00:00.000000/g' "${OUTFILE}.${testname}.stdout"
|
||||
sed -i -e 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\.[0-9]\{6\}/0000-00-00 00:00:00.000000/g' "${OUTFILE}.${testname}.stdout"
|
||||
sed -i -e 's#: .*/source$#: .../source#g' "${OUTFILE}.${testname}.stdout"
|
||||
sed -i -e 's#: .*/\.source\.txt$#: .../.source.txt#g' "${OUTFILE}.${testname}.stdout"
|
||||
sed -i -e '/secontext:/d' "${OUTFILE}.${testname}.stdout"
|
||||
sed -i -e 's/group: wheel/group: root/g' "${OUTFILE}.${testname}.stdout"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user