[Libguestfs] [PATCH] Windows: Display an error containing all missing when any are missing

Matthew Booth mbooth at redhat.com
Wed May 26 13:08:02 UTC 2010


Fixes RHBZ#596238
---
 lib/Sys/VirtV2V/Converter/Windows.pm |   57 +++++++++++++++------------------
 1 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/lib/Sys/VirtV2V/Converter/Windows.pm b/lib/Sys/VirtV2V/Converter/Windows.pm
index 8de2bcd..e55d0f3 100644
--- a/lib/Sys/VirtV2V/Converter/Windows.pm
+++ b/lib/Sys/VirtV2V/Converter/Windows.pm
@@ -181,9 +181,8 @@ sub _preconvert
     eval { $g->mkdir ("/temp"); };
     eval { $g->mkdir ("/temp/v2v"); };
 
-    _upload_viostor ($g, $tmpdir, $desc, $devices, $config);
+    _upload_files ($g, $tmpdir, $desc, $devices, $config);
     _add_viostor_to_registry ($g, $tmpdir, $desc, $devices, $config);
-    _upload_service ($g, $tmpdir, $desc, $devices, $config);
     _add_service_to_registry ($g, $tmpdir, $desc, $devices, $config);
 }
 
@@ -343,7 +342,7 @@ sub _add_service_to_registry
     $g->upload ($tmpdir . "/system", $system_filename);
 }
 
-sub _upload_viostor
+sub _upload_files
 {
     my $g = shift;
     my $tmpdir = shift;
@@ -351,39 +350,35 @@ sub _upload_viostor
     my $devices = shift;
     my $config = shift;
 
-    my $driverpath = "/windows/system32/drivers";
-    $driverpath = $g->case_sensitive_path ($driverpath);
+    # Check we have all required files
+    my @missing;
+    my %files;
 
-    my ($app, $depnames) = $config->match_app ($desc, "viostor", $desc->{arch});
-    $app = $config->get_transfer_path ($g, $app);
-    $g->cp ($app, $driverpath);
-}
+    for my $file ("viostor", "firstboot", "firstbootapp", "rhsrvany") {
+        my ($path) = $config->match_app ($desc, $file, $desc->{arch});
+        my $local = $config->get_transfer_path ($g, $path);
+        push (@missing, $path) unless ($g->exists($local));
 
-sub _upload_service
-{
-    my $g = shift;
-    my $tmpdir = shift;
-    my $desc = shift;
-    my $devices = shift;
-    my $config = shift;
-
-    my $path = "/temp/v2v";
-    $path = $g->case_sensitive_path ($path);
+        $files{$file} = $local;
+    }
 
-    my ($app, $depnames) =
-        $config->match_app ($desc, "firstboot", $desc->{arch});
-    $app = $config->get_transfer_path ($g, $app);
-    $g->cp ($app, $path);
+    # We can't proceed if there are any files missing
+    die(user_message(__x("Installation failed because the following ".
+                         "files referenced in the configuration file are ".
+                         "required, but missing: {list}",
+                         list => join(' ', @missing)))) if (@missing > 0);
 
-    ($app, $depnames) =
-        $config->match_app ($desc, "firstbootapp", $desc->{arch});
-    $app = $config->get_transfer_path ($g, $app);
-    $g->cp ($app, $path);
+    # Copy viostor into place
+    my $driverpath = "/windows/system32/drivers";
+    $driverpath = $g->case_sensitive_path ($driverpath);
+    $g->cp ($files{viostor}, $driverpath);
 
-    ($app, $depnames) =
-        $config->match_app ($desc, "rhsrvany", $desc->{arch});
-    $app = $config->get_transfer_path ($g, $app);
-    $g->cp ($app, $path);
+    # Copy other files into a temp directory
+    my $path = "/temp/v2v";
+    $path = $g->case_sensitive_path ($path);
+    $g->cp ($files{firstboot}, $path);
+    $g->cp ($files{firstbootapp}, $path);
+    $g->cp ($files{rhsrvany}, $path);
 }
 
 =back
-- 
1.7.0.1




More information about the Libguestfs mailing list