[Libguestfs] [PATCH 2/8] v2v: add basic support for the "deb" package manager

Pino Toscano ptoscano at redhat.com
Wed Aug 10 09:09:07 UTC 2016


On Tuesday, 9 August 2016 16:43:21 CEST Tomáš Golembiovský wrote:
> On Tue, 09 Aug 2016 15:24:21 +0200
> Pino Toscano <ptoscano at redhat.com> wrote:
> 
> > On Tuesday, 9 August 2016 13:55:36 CEST Tomáš Golembiovský wrote:
> > > On Mon,  8 Aug 2016 18:38:49 +0200
> > > Pino Toscano <ptoscano at redhat.com> wrote:
> > >   
> > > > Implement the 'remove', 'file_list_of_package', and 'file_owner' methods
> > > > of the Linux module for the "deb" package manager (dpkg basically, on
> > > > Debian and derived distributions).
> > > > 
> > > > Also allow it for the main conversion code.
> > > > ---
> > > >  v2v/convert_linux.ml |  2 +-
> > > >  v2v/linux.ml         | 23 +++++++++++++++++++++++
> > > >  2 files changed, 24 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
> > > > index 4b1ce99..65796d6 100644
> > > > --- a/v2v/convert_linux.ml
> > > > +++ b/v2v/convert_linux.ml
> > > > @@ -79,7 +79,7 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
> > > >      | "sles" | "suse-based" | "opensuse" -> `SUSE_family
> > > >      | _ -> assert false in
> > > >  
> > > > -  assert (inspect.i_package_format = "rpm");
> > > > +  assert (inspect.i_package_format = "rpm" || inspect.i_package_format = "deb");
> > > >  
> > > >    (* We use Augeas for inspection and conversion, so initialize it early. *)
> > > >    Linux.augeas_init g;
> > > > diff --git a/v2v/linux.ml b/v2v/linux.ml
> > > > index ed639c1..5713f64 100644
> > > > --- a/v2v/linux.ml
> > > > +++ b/v2v/linux.ml
> > > > @@ -48,6 +48,10 @@ and do_remove g inspect packages =
> > > >    assert (List.length packages > 0);
> > > >    let package_format = inspect.i_package_format in
> > > >    match package_format with
> > > > +  | "deb" ->
> > > > +    let cmd = [ "dpkg"; "--purge" ] @ packages in
> > > > +    let cmd = Array.of_list cmd in
> > > > +    ignore (g#command cmd);
> > > >    | "rpm" ->
> > > >      let cmd = [ "rpm"; "-e" ] @ packages in
> > > >      let cmd = Array.of_list cmd in
> > > > @@ -61,6 +65,12 @@ let file_list_of_package (g : Guestfs.guestfs) inspect app =
> > > >    let package_format = inspect.i_package_format in
> > > >  
> > > >    match package_format with
> > > > +  | "deb" ->
> > > > +    let cmd = [| "dpkg"; "-L"; app.G.app2_name |] in
> > > > +    debug "%s" (String.concat " " (Array.to_list cmd));
> > > > +    let files = g#command_lines cmd in
> > > > +    let files = Array.to_list files in
> > > > +    List.sort compare files
> > > >    | "rpm" ->
> > > >      (* Since RPM allows multiple packages installed with the same
> > > >       * name, always check the full ENVR here (RHBZ#1161250).
> > > > @@ -98,6 +108,19 @@ let file_list_of_package (g : Guestfs.guestfs) inspect app =
> > > >  let rec file_owner (g : G.guestfs) inspect path =
> > > >    let package_format = inspect.i_package_format in
> > > >    match package_format with
> > > > +  | "deb" ->
> > > > +      let cmd = [| "dpkg"; "-S"; path |] in
> > > > +      debug "%s" (String.concat " " (Array.to_list cmd));
> > > > +      let lines =
> > > > +        try g#command_lines cmd  
> > > 
> > > This is not good. dpkg-query command behaves differently from rpm.  
> > 
> > AFAIR, dpkg doesn't allow a file to be owned by different packages
> > (and even if it does, it will complain hard when the file is not exactly
> > the same in all the packages).
> 
> Good point. I take it then that the function should focus only on files
> (as the name suggests).

Yes, although the only usage of it is to check for (un)owned directories
with xenpv modules.  IMHO the current approach is slightly wrong: we are
checking whether a directory is owned and removing all the content in
it, but we should better check whether the files are owned, and remove
them.

> > This is not what happens with directories, which can be owned by every
> > package (and indeed usually every debian package owns all the
> > directories, / included, that contain the shipped files).
> > 
> > There could be also multiarch to take into account, but that's something
> > that could be dealt with later.
> 
> Still the fact remains, that the returned string contains not just a
> package name, but also the path itself. I.e: "package: /some/file"

D'oh, I realize now I send the wrong patch... I'll followup with a
fixed version of this.  Thanks for the notice of the silly mistake.

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20160810/73e3542e/attachment.sig>


More information about the Libguestfs mailing list