23
23
operation ,
24
24
OperationError ,
25
25
OperationTypeError ,
26
+ QuoteString ,
26
27
RsyncCommand ,
27
28
StringCommand ,
28
29
)
29
30
from pyinfra .api .command import make_formatted_string_command
30
- from pyinfra .api .connectors .util import escape_unix_path
31
31
from pyinfra .api .util import (
32
32
get_file_sha1 ,
33
33
get_path_permissions_mode ,
@@ -363,8 +363,6 @@ def replace(
363
363
)
364
364
'''
365
365
366
- path = escape_unix_path (path )
367
-
368
366
existing_lines = host .fact .find_in_file (path , match )
369
367
370
368
# Only do the replacement if the file does not exist (it may be created earlier)
@@ -592,8 +590,6 @@ def get(
592
590
)
593
591
'''
594
592
595
- src = escape_unix_path (src )
596
-
597
593
if add_deploy_dir and state .deploy_dir :
598
594
dest = os_path .join (state .deploy_dir , dest )
599
595
@@ -667,8 +663,6 @@ def put(
667
663
)
668
664
'''
669
665
670
- dest = escape_unix_path (dest )
671
-
672
666
# Upload IO objects as-is
673
667
if hasattr (src , 'read' ):
674
668
local_file = src
@@ -816,8 +810,6 @@ def template(
816
810
{% endfor %}
817
811
'''
818
812
819
- dest = escape_unix_path (dest )
820
-
821
813
if state .deploy_dir :
822
814
src = os_path .join (state .deploy_dir , src )
823
815
@@ -934,19 +926,18 @@ def link(
934
926
if present and not target :
935
927
raise OperationError ('If present is True target must be provided' )
936
928
937
- path = escape_unix_path (path )
938
929
info = host .fact .link (path )
939
930
940
931
# Not a link?
941
932
if info is False :
942
933
raise OperationError ('{0} exists and is not a link' .format (path ))
943
934
944
- add_cmd = 'ln{0} {1} {2}' .format (
945
- ' -s' if symbolic else '' ,
946
- target , path ,
947
- )
935
+ add_args = ['ln' ]
936
+ if symbolic :
937
+ add_args .append ('-s' )
948
938
949
- remove_cmd = 'rm -f {0}' .format (path )
939
+ add_cmd = StringCommand (' ' .join (add_args ), QuoteString (target ), QuoteString (path ))
940
+ remove_cmd = StringCommand ('rm' , '-f' , QuoteString (path ))
950
941
951
942
# No link and we want it
952
943
if not assume_present and info is None and present :
@@ -1060,7 +1051,6 @@ def file(
1060
1051
_validate_path (path )
1061
1052
1062
1053
mode = ensure_mode_int (mode )
1063
- path = escape_unix_path (path )
1064
1054
info = host .fact .file (path )
1065
1055
1066
1056
# Not a file?!
@@ -1072,7 +1062,7 @@ def file(
1072
1062
if create_remote_dir :
1073
1063
yield _create_remote_dir (state , host , path , user , group )
1074
1064
1075
- yield 'touch {0}' . format (path )
1065
+ yield StringCommand ( 'touch' , QuoteString (path ) )
1076
1066
1077
1067
if mode :
1078
1068
yield chmod (path , mode )
@@ -1087,7 +1077,7 @@ def file(
1087
1077
1088
1078
# It exists and we don't want it
1089
1079
elif (assume_present or info ) and not present :
1090
- yield 'rm -f {0}' . format (path )
1080
+ yield StringCommand ( 'rm' , '-f' , QuoteString (path ) )
1091
1081
host .fact ._delete ('file' , args = (path ,))
1092
1082
1093
1083
# It exists & we want to ensure its state
@@ -1100,7 +1090,7 @@ def file(
1100
1090
1101
1091
if touch :
1102
1092
changed = True
1103
- yield 'touch {0}' . format (path )
1093
+ yield StringCommand ( 'touch' , QuoteString (path ) )
1104
1094
1105
1095
# Check mode
1106
1096
if mode and (not info or info ['mode' ] != mode ):
@@ -1176,7 +1166,6 @@ def directory(
1176
1166
_validate_path (path )
1177
1167
1178
1168
mode = ensure_mode_int (mode )
1179
- path = escape_unix_path (path )
1180
1169
info = host .fact .directory (path )
1181
1170
1182
1171
# Not a directory?!
@@ -1188,7 +1177,7 @@ def directory(
1188
1177
1189
1178
# Doesn't exist & we want it
1190
1179
if not assume_present and info is None and present :
1191
- yield 'mkdir -p {0}' . format (path )
1180
+ yield StringCommand ( 'mkdir' , '-p' , QuoteString (path ) )
1192
1181
if mode :
1193
1182
yield chmod (path , mode , recursive = recursive )
1194
1183
if user or group :
@@ -1202,7 +1191,7 @@ def directory(
1202
1191
1203
1192
# It exists and we don't want it
1204
1193
elif (assume_present or info ) and not present :
1205
- yield 'rm -rf {0}' . format (path )
1194
+ yield StringCommand ( 'rm' , ' -rf' , QuoteString (path ) )
1206
1195
host .fact ._delete ('directory' , args = (path ,))
1207
1196
1208
1197
# It exists & we want to ensure its state
0 commit comments