2323 operation ,
2424 OperationError ,
2525 OperationTypeError ,
26+ QuoteString ,
2627 RsyncCommand ,
2728 StringCommand ,
2829)
2930from pyinfra .api .command import make_formatted_string_command
30- from pyinfra .api .connectors .util import escape_unix_path
3131from pyinfra .api .util import (
3232 get_file_sha1 ,
3333 get_path_permissions_mode ,
@@ -363,8 +363,6 @@ def replace(
363363 )
364364 '''
365365
366- path = escape_unix_path (path )
367-
368366 existing_lines = host .fact .find_in_file (path , match )
369367
370368 # Only do the replacement if the file does not exist (it may be created earlier)
@@ -592,8 +590,6 @@ def get(
592590 )
593591 '''
594592
595- src = escape_unix_path (src )
596-
597593 if add_deploy_dir and state .deploy_dir :
598594 dest = os_path .join (state .deploy_dir , dest )
599595
@@ -667,8 +663,6 @@ def put(
667663 )
668664 '''
669665
670- dest = escape_unix_path (dest )
671-
672666 # Upload IO objects as-is
673667 if hasattr (src , 'read' ):
674668 local_file = src
@@ -816,8 +810,6 @@ def template(
816810 {% endfor %}
817811 '''
818812
819- dest = escape_unix_path (dest )
820-
821813 if state .deploy_dir :
822814 src = os_path .join (state .deploy_dir , src )
823815
@@ -934,19 +926,18 @@ def link(
934926 if present and not target :
935927 raise OperationError ('If present is True target must be provided' )
936928
937- path = escape_unix_path (path )
938929 info = host .fact .link (path )
939930
940931 # Not a link?
941932 if info is False :
942933 raise OperationError ('{0} exists and is not a link' .format (path ))
943934
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' )
948938
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 ))
950941
951942 # No link and we want it
952943 if not assume_present and info is None and present :
@@ -1060,7 +1051,6 @@ def file(
10601051 _validate_path (path )
10611052
10621053 mode = ensure_mode_int (mode )
1063- path = escape_unix_path (path )
10641054 info = host .fact .file (path )
10651055
10661056 # Not a file?!
@@ -1072,7 +1062,7 @@ def file(
10721062 if create_remote_dir :
10731063 yield _create_remote_dir (state , host , path , user , group )
10741064
1075- yield 'touch {0}' . format (path )
1065+ yield StringCommand ( 'touch' , QuoteString (path ) )
10761066
10771067 if mode :
10781068 yield chmod (path , mode )
@@ -1087,7 +1077,7 @@ def file(
10871077
10881078 # It exists and we don't want it
10891079 elif (assume_present or info ) and not present :
1090- yield 'rm -f {0}' . format (path )
1080+ yield StringCommand ( 'rm' , '-f' , QuoteString (path ) )
10911081 host .fact ._delete ('file' , args = (path ,))
10921082
10931083 # It exists & we want to ensure its state
@@ -1100,7 +1090,7 @@ def file(
11001090
11011091 if touch :
11021092 changed = True
1103- yield 'touch {0}' . format (path )
1093+ yield StringCommand ( 'touch' , QuoteString (path ) )
11041094
11051095 # Check mode
11061096 if mode and (not info or info ['mode' ] != mode ):
@@ -1176,7 +1166,6 @@ def directory(
11761166 _validate_path (path )
11771167
11781168 mode = ensure_mode_int (mode )
1179- path = escape_unix_path (path )
11801169 info = host .fact .directory (path )
11811170
11821171 # Not a directory?!
@@ -1188,7 +1177,7 @@ def directory(
11881177
11891178 # Doesn't exist & we want it
11901179 if not assume_present and info is None and present :
1191- yield 'mkdir -p {0}' . format (path )
1180+ yield StringCommand ( 'mkdir' , '-p' , QuoteString (path ) )
11921181 if mode :
11931182 yield chmod (path , mode , recursive = recursive )
11941183 if user or group :
@@ -1202,7 +1191,7 @@ def directory(
12021191
12031192 # It exists and we don't want it
12041193 elif (assume_present or info ) and not present :
1205- yield 'rm -rf {0}' . format (path )
1194+ yield StringCommand ( 'rm' , ' -rf' , QuoteString (path ) )
12061195 host .fact ._delete ('directory' , args = (path ,))
12071196
12081197 # It exists & we want to ensure its state
0 commit comments