Skip to content

Commit

Permalink
Merge pull request #184 from xcp-ng/fix/xcpng-fs-diff.py
Browse files Browse the repository at this point in the history
fix/xcpng-fs-diff.py
  • Loading branch information
tescande authored Dec 22, 2023
2 parents ae12e90 + 4a45b24 commit e313ff2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 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,8 +179,7 @@ def remote_diff(host1, host2, filename):
file2 = None

# check remote files are text files
args = ["ssh", "root@{}".format(host1), "file", "-b", filename]
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 Expand Up @@ -297,6 +297,9 @@ def main():
save_reference_files(ref_files, args.save_ref)

if ref_files is None or args.test_host is None:
if args.save_ref:
return 0

print("\nMissing parameters. Try --help", file=sys.stderr)
return -1

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[pycodestyle]
max-line-length=120
ignore=E261,E302,E305,W503
exclude=data.py,vm_data.py
exclude=data.py,vm_data.py,.git

[pydocstyle]
ignore=D100,D101,D102,D103,D104,D105,D106,D107,D203,D210,D212,D401,D403

0 comments on commit e313ff2

Please sign in to comment.