kaxil commented on code in PR #73352:
URL: https://github.com/apache/airflow/pull/73352#discussion_r4462762656


##########
providers/ssh/src/airflow/providers/ssh/utils/remote_job.py:
##########
@@ -271,37 +271,43 @@ def build_windows_wrapper_command(
             env_setup += f"$env:{key} = '{escaped_value}'; "
 
     def ps_escape(s: str) -> str:
+        return s.replace("`", "``").replace('"', '`"')

Review Comment:
   Fixed in c1bccb4: paths are single-quoted now, typographic quotes included, 
only a leading `$env:NAME` is expanded, and every cmdlet gets `-LiteralPath`, 
so `$`, backticks and brackets stay part of the directory name.



##########
providers/ssh/src/airflow/providers/ssh/utils/remote_job.py:
##########
@@ -271,37 +271,43 @@ def build_windows_wrapper_command(
             env_setup += f"$env:{key} = '{escaped_value}'; "
 
     def ps_escape(s: str) -> str:
+        return s.replace("`", "``").replace('"', '`"')
+
+    def ps_escape_sq(s: str) -> str:
         return s.replace("'", "''")
 
     job_dir = ps_escape(paths.job_dir)
-    log_file = ps_escape(paths.log_file)
-    exit_code_file = ps_escape(paths.exit_code_file)
-    exit_code_tmp = ps_escape(paths.exit_code_tmp_file)
-    pid_file = ps_escape(paths.pid_file)
-    status_file = ps_escape(paths.status_file)
+    sep = paths.sep
+    job_id = ps_escape_sq(paths.job_id)
     escaped_command = ps_escape(command)
-    job_id = ps_escape(paths.job_id)
 
-    child_script = f"""$ErrorActionPreference = 'Continue'
-$env:LOG_FILE = '{log_file}'
-$env:STATUS_FILE = '{status_file}'
+    # Use $d and $b for directories to avoid passing long paths multiple times.
+    # Write command to disk to avoid double base64 encoding.
+    # Add-Content writes each pipeline object to disk immediately (no block 
buffering),
+    # giving real-time log updates.
+    # Launch as Win32_Process so that it doesn't die when SSH exits.
+    child_script = f"""$ErrorActionPreference = "Continue"
+$b = $PSScriptRoot
+$env:LOG_FILE = "$b{sep}stdout.log"
+$env:STATUS_FILE = "$b{sep}status"
 {env_setup}
-{escaped_command}
+{escaped_command} 2>&1 | Add-Content -Path $env:LOG_FILE
 $ec = $LASTEXITCODE
 if ($null -eq $ec) {{ $ec = 0 }}
-Set-Content -NoNewline -Path '{exit_code_tmp}' -Value $ec
-Move-Item -Force -Path '{exit_code_tmp}' -Destination '{exit_code_file}'
+Set-Content -NoNewline -Path "$b{sep}exit_code.tmp" -Value $ec
+Move-Item -Force -Path "$b{sep}exit_code.tmp" -Destination "$b{sep}exit_code"
 """
-    child_script_bytes = child_script.encode("utf-16-le")
-    encoded_script = base64.b64encode(child_script_bytes).decode("ascii")
 
-    wrapper = f"""$jobDir = '{job_dir}'
-New-Item -ItemType Directory -Force -Path $jobDir | Out-Null
-$log = '{log_file}'
-'' | Set-Content -Path $log
+    wrapper = f"""$d = "{job_dir}"
+New-Item -ItemType Directory -Force -Path $d | Out-Null
+$sf = "$d{sep}job.ps1"
+@'
+{child_script}'@ | Set-Content -Path $sf -Encoding UTF8
+'' | Set-Content -Path "$d{sep}stdout.log"

Review Comment:
   Fixed in c1bccb4: the log is UTF-8 without a BOM, and the tail sends the 
bytes as they are, since printing them re-encodes them in the SSH session's 
code page, which the trigger's UTF-8 decoding rejects for non-ASCII text.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to