--- febootstrap_debian.ml | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/febootstrap_debian.ml b/febootstrap_debian.ml index 745a383..0bf50fc 100644 --- a/febootstrap_debian.ml +++ b/febootstrap_debian.ml @@ -27,6 +27,7 @@ open Febootstrap_cmdline (* Create a temporary directory for use by all the functions in this file. *) let tmpdir = tmpdir () +let apt_cache_dir = "/var/cache/apt/archives" let debian_detect () = file_exists "/etc/debian_version" && @@ -45,6 +46,25 @@ let debian_resolve_dependencies_and_download names = not (List.exists (fun re -> Str.string_match re name 0) excludes) ) pkgs in + (* Copy packages that are already present in cache *) + let cmd = sprintf "apt-get --print-uris download %s" + (String.concat " " (List.map Filename.quote pkgs)) in + let present_pkgs = + List.filter (fun filename -> file_exists (sprintf "%s/%s" apt_cache_dir filename)) + (List.map (fun line -> + Scanf.sscanf line "%s %s %i %s" + (fun url filename size checksum -> filename)) + (run_command_get_lines cmd)) in + let cmd = + sprintf "cd %s && cp -t . %s" + (Filename.quote tmpdir) + (String.concat " " + (List.map (fun filename -> + (Filename.quote + (sprintf "%s/%s" apt_cache_dir filename))) + present_pkgs)) in + run_command cmd; + (* Download the packages. *) let cmd = sprintf "cd %s && apt-get download %s" -- 1.7.5.4