Skip to content

Commit

Permalink
xcpng-fs-diff.py: Quote filenames
Browse files Browse the repository at this point in the history
This fixes the script for filenames with special characters like spaces
and quotes.

Signed-off-by: Thierry Escande <[email protected]>
  • Loading branch information
tescande committed Dec 22, 2023
1 parent 2ea9fc4 commit 9e1d48a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions scripts/xcpng-fs-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import json
import tempfile
import os
import shlex
from fnmatch import fnmatch
from enum import Enum

Expand Down Expand Up @@ -128,14 +129,14 @@ def ssh_get_files(host, file_type, folders):
elif md5sum:
# This will make one call to md5sum with all files passed as parameter
# This is much more efficient than using find '-exec md5sum {}'
find_cmd += " | xargs md5sum"
find_cmd += " -print0 | xargs -0 md5sum"

rawres = ssh_cmd(host, find_cmd)

res = dict()
for line in rawres.splitlines():
entry = line.split()
res[entry[1]] = entry[0]
entry = line.split(' ', 1)
res[entry[1].strip()] = entry[0].strip()

return res

Expand All @@ -157,7 +158,7 @@ def sftp_get(host, remote_file, local_file):
opts = '-o "StrictHostKeyChecking no" -o "LogLevel ERROR" -o "UserKnownHostsFile /dev/null"'

args = "sftp {} -b - root@{}".format(opts, host)
input = bytes("get {} {}".format(remote_file, local_file), 'utf-8')
input = bytes("get {} {}".format(shlex.quote(remote_file), shlex.quote(local_file)), 'utf-8')
res = subprocess.run(
args,
input=input,
Expand All @@ -178,7 +179,7 @@ def remote_diff(host1, host2, filename):
file2 = None

# check remote files are text files
cmd = "file -b {}".format(filename)
cmd = "file -b {}".format(shlex.quote(filename))
file_type = ssh_cmd(host1, cmd)
if not file_type.lower().startswith("ascii"):
print("Binary file. Not showing diff")
Expand Down

0 comments on commit 9e1d48a

Please sign in to comment.