[Libguestfs] [supermin 3/3] Use the file tuple up to the point where files are copied into the filesystem / chroot

Richard W.M. Jones rjones at redhat.com
Tue Mar 11 09:49:22 UTC 2014


On Mon, Mar 10, 2014 at 11:33:51AM +0100, Hilko Bengen wrote:
>  and munge files =
> -  let files = List.sort compare files in
> +  let paths =
> +    List.sort compare
> +      (List.map (fun file -> file.ft_path) files) in
>  
>    let rec stat_is_dir dir =
>      try (stat dir).st_kind = S_DIR with Unix_error _ -> false
> @@ -336,7 +338,7 @@ and munge files =
>    in
>  
>    let insert_dir, dir_seen =
> -    let h = Hashtbl.create (List.length files) in
> +    let h = Hashtbl.create (List.length paths) in
>      let insert_dir dir = Hashtbl.replace h dir true in
>      let dir_seen dir = Hashtbl.mem h dir in
>      insert_dir, dir_seen
> @@ -385,10 +387,17 @@ and munge files =
>        (* Have we seen this parent directory before? *)
>        let dir = Filename.dirname file in
>        if not (dir_seen dir) then
> -        loop (dir :: file :: rest)
> +        loop (dir :: rest)

Why did file get dropped from the list here?

>        else
> -        file :: loop rest
> +        loop rest

And here?

>    in
> -  let files = loop files in
> +  let dir_paths = loop paths in
> +
> +  let dirs = List.map (fun path ->
> +    {ft_path = path; ft_source_path = path; ft_config = false}
> +  ) dir_paths in
> +  let files = List.filter (fun file ->
> +    not (dir_seen file.ft_path)
> +  ) files in
>  
> -  files
> +  dirs @ files

This seems to change the result of this (very important and complex)
function.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)




More information about the Libguestfs mailing list