[Libguestfs] [PATCH] v2v: fixed file_owner function

Tomáš Golembiovský tgolembi at redhat.com
Mon Aug 1 12:46:14 UTC 2016


What was happening in file_owner function did not match the description
in the comment. When a path is owned by multiple packages the returned
string was in fact a concatenation of the names of all packages that own
it. E.g. for `Linux.is_file_owned g inspect "/etc"` the returned value
was "filesystemyum" (i.e. "filesystem" + "yum").

Signed-off-by: Tomáš Golembiovský <tgolembi at redhat.com>
---
 v2v/linux.ml | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/v2v/linux.ml b/v2v/linux.ml
index d20194b..aeff5c5 100644
--- a/v2v/linux.ml
+++ b/v2v/linux.ml
@@ -99,14 +99,18 @@ let rec file_owner g inspect path =
       (* Although it is possible in RPM for multiple packages to own
        * a file, this deliberately only returns one package.
        *)
-      let cmd = [| "rpm"; "-qf"; "--qf"; "%{NAME}"; path |] in
+      let cmd = [| "rpm"; "-qf"; "--qf"; "%{NAME}\\n"; path |] in
       debug "%s" (String.concat " " (Array.to_list cmd));
-      (try g#command cmd
+      (try
+         let pkgs = g#command_lines cmd in
+         pkgs.(0)
        with Guestfs.Error msg as exn ->
          if String.find msg "is not owned" >= 0 then
            raise Not_found
          else
            raise exn
+       | Invalid_argument msg ->
+           raise Not_found
       )
 
   | format ->
-- 
2.9.2





More information about the Libguestfs mailing list