From 1b2952c1a69ac96d55be17a249f208e5285b1e9b Mon Sep 17 00:00:00 2001 From: Borjan Tchakaloff Date: Fri, 1 Jan 2021 16:38:50 +0100 Subject: [PATCH] syncthing_folder: Keep existing device ordering Keep the existing list of devices if it contains the expected devices. This change fixes the current/expected configurations comparison on devices ordering. --- library/storage/syncthing/syncthing_folder.py | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/library/storage/syncthing/syncthing_folder.py b/library/storage/syncthing/syncthing_folder.py index 0ae642c..7b13579 100644 --- a/library/storage/syncthing/syncthing_folder.py +++ b/library/storage/syncthing/syncthing_folder.py @@ -177,11 +177,25 @@ def post_config(module, config, result): module.fail_json(msg='Error occured while posting new config', **result) # Returns an object of a new folder -def create_folder(params): - folder = { +def create_folder(params, current_device_ids): + # Collect wanted devices to share folder with. + # Note that the sequence ordering matters, so we stick with lists + # instead of sets. + device_ids = ( + current_device_ids if set(current_device_ids) == set(params['devices']) + else params['devices'] + ) + devices = [ + { + 'deviceID': device_id, + 'introducedBy': '', + } for device_id in device_ids + ] + + return { 'autoNormalize': True, 'copiers': 0, - 'devices': [], + 'devices': devices, 'disableSparseFiles': False, 'disableTempIndexes': False, 'filesystemType': 'basic', @@ -214,15 +228,6 @@ def create_folder(params): 'weakHashThresholdPct': 25 } - # Collect wanted devices to share folder with - for device_id in params['devices']: - folder['devices'].append({ - 'deviceID': device_id, - 'introducedBy': '', - }) - - return folder - def run_module(): # module arguments module_args = url_argument_spec() @@ -275,7 +280,8 @@ def run_module(): break else: folder_config = get_folder_config(module.params['id'], config) - folder_config_wanted = create_folder(module.params) + folder_config_devices = [d['deviceID'] for d in folder_config['devices']] + folder_config_wanted = create_folder(module.params, folder_config_devices) if folder_config is None: config['folders'].append(folder_config_wanted)