From ae475a04f2cb464862e366ce00a01cf7af132ac6 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Fri, 15 Nov 2019 16:07:00 -0700 Subject: [PATCH] Try renaming update folder(s) if deletion fails --- .bin/Scripts/functions/windows_updates.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.bin/Scripts/functions/windows_updates.py b/.bin/Scripts/functions/windows_updates.py index 3618fbb2..3d72f90b 100644 --- a/.bin/Scripts/functions/windows_updates.py +++ b/.bin/Scripts/functions/windows_updates.py @@ -1,5 +1,7 @@ # Wizard Kit: Functions - Windows updates +import pathlib + from functions.common import * @@ -63,7 +65,11 @@ def disable_windows_updates(): indent=indent, width=width, function=delete_folder, folder_path=folder_path) if not result['CS']: - raise GenericError('Failed to remove folder {}'.format(folder_path)) + try: + new_path = pathlib.path(folder_path).with_suffix('.bak') + os.rename(folder_path, new_path) + except OSError: + raise GenericError('Failed to remove folder {}'.format(folder_path)) def enable_service(service_name, start_type='auto'):