domain.py: Give some advice if the schema upgrade command fails
authorGarming Sam <garming@catalyst.net.nz>
Tue, 27 Feb 2018 23:38:12 +0000 (12:38 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 1 Mar 2018 08:53:45 +0000 (09:53 +0100)
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
python/samba/netcmd/domain.py

index 7b23fa794de5c34e02ba73f0479c8bf69cb08b6e..d3b9b0ccf6fd9af38859e88bca2848f42aaa6cb8 100644 (file)
@@ -4150,9 +4150,14 @@ class cmd_domain_schema_upgrade(Command):
                 # Apply patches if we parsed the Schema-Updates.md file
                 diff = os.path.abspath(os.path.join(diff_dir, update + '.diff'))
                 if temp_folder and os.path.exists(diff):
-                    p = subprocess.Popen(['patch', update, '-i', diff],
-                                         stdout=subprocess.PIPE,
-                                         stderr=subprocess.PIPE, cwd=temp_folder)
+                    try:
+                        p = subprocess.Popen(['patch', update, '-i', diff],
+                                             stdout=subprocess.PIPE,
+                                             stderr=subprocess.PIPE, cwd=temp_folder)
+                    except (OSError, IOError):
+                        shutil.rmtree(temp_folder)
+                        raise CommandError("Failed to upgrade schema. Check if 'patch' is installed.")
+
                     stdout, stderr = p.communicate()
 
                     if p.returncode: