Improve JSON output a bit more.
authorWayne Davison <wayne@opencoder.net>
Thu, 20 Oct 2022 17:54:14 +0000 (10:54 -0700)
committerWayne Davison <wayne@opencoder.net>
Fri, 21 Oct 2022 00:50:06 +0000 (17:50 -0700)
NEWS.md
support/json-rsync-version
usage.c

diff --git a/NEWS.md b/NEWS.md
index 24862dd08c780729997582b51159315d1d187519..ad1aaee0dfd59af9530d4fa7b45bdea6eaa7c343 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
   environment var for how to customize this.
 
 - Improved the xattr hash table to use a 64-bit key without slowing down the
-  key's computation.  This should make extra sure that a collision doesn't
+  key's computation.  This should make extra sure that a hash collision doesn't
   happen.
 
 - If the `--version` option is repeated (e.g. `-VV`) then the information is
-  output in a (still fairly readable) JSON format.  Client side only.
+  output in a (still readable) JSON format.  Client side only.
 
 - The script `support/json-rsync-version` is available to get the JSON style
   version output from any rsync.  The script accepts either text on stdin
   **or** an arg that specifies an rsync executable to run with a doubled
   `--version` option.  If the text we get isn't already in JSON format, it is
   converted. Newer rsync versions will provide more complete json info than
-  older rsync versions.
+  older rsync versions. Various tweaks are made to keep the flag names
+  consistent across versions.
 
 - The [`use chroot`](rsyncd.conf.5#) daemon parameter now defaults to "unset"
   so that rsync can use chroot when it works and a sanitized copy when chroot
index bf5684b74c2ce261a1ea36d5f48b0b812b2b6dd4..31fed7f1eb3bd9bd5785f21393150adcd8389c01 100755 (executable)
@@ -2,6 +2,17 @@
 
 import sys, argparse, subprocess, json
 
+TWEAK_NAME = {
+        'asm': 'asm_roll',
+        'ASM': 'asm_roll',
+        'hardlink_special': 'hardlink_specials',
+        'protect_args': 'secluded_args',
+        'protected_args': 'secluded_args',
+        'SIMD': 'SIMD_roll',
+    }
+
+MOVE_OPTIM = set('asm_roll SIMD_roll'.split())
+
 def main():
     if not args.rsync or args.rsync == '-':
         ver_out = sys.stdin.read().strip()
@@ -11,6 +22,7 @@ def main():
         print(ver_out)
         return
     info = { }
+    misplaced_optims = { }
     for line in ver_out.splitlines():
         if line.startswith('rsync '):
             prog, vstr, ver, pstr, vstr2, proto = line.split()
@@ -40,13 +52,16 @@ def main():
                         elif val.endswith('-bit'):
                             var = var[:-1] + '_bits'
                             val = int(val.split('-')[0])
-                        if var == 'protect-args':
-                            var = 'secluded-args'
                     else:
                         var = x
                         val = True
                     var = var.replace(' ', '_').replace('-', '_')
-                    info[sect_name][var] = val
+                    if var in TWEAK_NAME:
+                        var = TWEAK_NAME[var]
+                    if sect_name[0] != 'o' and var in MOVE_OPTIM:
+                        misplaced_optims[var] = val
+                    else:
+                        info[sect_name][var] = val
             else:
                 info[sect_name] += [ x for x in line.split() if not x.startswith('(') ]
         elif line == '':
@@ -58,10 +73,12 @@ def main():
     for chk in 'capabilities optimizations'.split():
         if chk not in info:
             info[chk] = { }
+    if misplaced_optims:
+        info['optimizations'].update(misplaced_optims)
     for chk in 'checksum_list compress_list daemon_auth_list'.split():
         if chk not in info:
             info[chk] = [ ]
-    info['license'] = 'GPL3'
+    info['license'] = 'GPLv3' if ver[0] == '3' else 'GPLv2'
     info['caveat'] = 'rsync comes with ABSOLUTELY NO WARRANTY'
     print(json.dumps(info))
 
diff --git a/usage.c b/usage.c
index 2db64767c6ced25701fc24763ad86b99205cf14c..a5b59ad823b7b5d45fe658228ab03370d2786039 100644 (file)
--- a/usage.c
+++ b/usage.c
@@ -290,7 +290,7 @@ void print_rsync_version(enum logcode f)
        output_nno_list(f, "Daemon auth list", &valid_auth_checksums);
 
        if (f == FNONE) {
-               json_line("license", "GPL3");
+               json_line("license", "GPLv3");
                json_line("caveat", "rsync comes with ABSOLUTELY NO WARRANTY");
                printf("\n}\n");
                return;