You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

acquire.cc 29 KiB

* merged from main Patches applied: * apt@packages.debian.org/apt--main--0--patch-106 Restore lost changelog entries * apt@packages.debian.org/apt--main--0--patch-107 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-108 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-109 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-110 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * michael.vogt@ubuntu.com--2005/apt--fixes--0--patch-5 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--base-0 tag of apt@packages.debian.org/apt--main--0--patch-85 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-1 * inital proof of concept code, understands what dpkg tells it already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-2 * progress reporting works now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-3 * added "APT::Status-Fd" variable * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-4 * do i18n now too * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-5 * define N_(x) if it is not defined already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-6 * PackageManager::DoInstall(int status_fd) added (does not break the ABI) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-7 * merged with apt--fixes--0 to make it build again * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-8 * added support for "error" and "conffile-prompt" messages from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-9 merge with main * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-10 * use sizeof() for all snprintf() uses; fix a potential line break problem in the status reading code; changed the N_() to _() calls * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-11 * added APT::KeepFDs configuration list for file descriptors that apt should leave open (needed for various frontends like debconf, synaptic) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-12 * fixed a API breakage * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-13 * doc added, should be releasable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-14 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-15 * more source comments, added Debug::DpkgPM debug code to inspect the dpkg<->apt communication, broke the abi (ok with matt) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-16 * the progress reporting has it's own "Debug::pkgDPkgProgressReporting" debug variable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-17 * merged PackageOps and TranslatedPackageOps into a single Map with the new DpkgState struct * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-18 * clear the APT::Keep-Fds configuration when it's no longer needed * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-19 * rewrote the reading from dpkg so that it never blocks * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-20 * merged the two status arrays into one * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-21 * added support for download progress reporting too (for Kamion and base-config) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-22 * ABI break; added Configuration::Clear(string List, {int,string} value) added (to remove a single Value from a list); test/conf_clear.cc added * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-23 * remvoed a debug string * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-24 * soname changed, fixed a bug in the parsing code when dpkg send the same state more than once (at the end) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-25 * merged with apt@packages.debian.org/apt--main--0, added changelog entry for the 0.6.40.1 upload * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-26 * fix a bug when out-of-order states are send from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-27 * changelog update * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-28 * a real changelog entry now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-29 * changelog finalized * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-30 * propper (and sane) support for pmerror and pmconffile added
16 years ago
* merged from main Patches applied: * apt@packages.debian.org/apt--main--0--patch-106 Restore lost changelog entries * apt@packages.debian.org/apt--main--0--patch-107 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-108 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-109 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-110 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * michael.vogt@ubuntu.com--2005/apt--fixes--0--patch-5 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--base-0 tag of apt@packages.debian.org/apt--main--0--patch-85 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-1 * inital proof of concept code, understands what dpkg tells it already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-2 * progress reporting works now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-3 * added "APT::Status-Fd" variable * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-4 * do i18n now too * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-5 * define N_(x) if it is not defined already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-6 * PackageManager::DoInstall(int status_fd) added (does not break the ABI) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-7 * merged with apt--fixes--0 to make it build again * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-8 * added support for "error" and "conffile-prompt" messages from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-9 merge with main * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-10 * use sizeof() for all snprintf() uses; fix a potential line break problem in the status reading code; changed the N_() to _() calls * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-11 * added APT::KeepFDs configuration list for file descriptors that apt should leave open (needed for various frontends like debconf, synaptic) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-12 * fixed a API breakage * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-13 * doc added, should be releasable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-14 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-15 * more source comments, added Debug::DpkgPM debug code to inspect the dpkg<->apt communication, broke the abi (ok with matt) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-16 * the progress reporting has it's own "Debug::pkgDPkgProgressReporting" debug variable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-17 * merged PackageOps and TranslatedPackageOps into a single Map with the new DpkgState struct * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-18 * clear the APT::Keep-Fds configuration when it's no longer needed * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-19 * rewrote the reading from dpkg so that it never blocks * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-20 * merged the two status arrays into one * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-21 * added support for download progress reporting too (for Kamion and base-config) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-22 * ABI break; added Configuration::Clear(string List, {int,string} value) added (to remove a single Value from a list); test/conf_clear.cc added * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-23 * remvoed a debug string * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-24 * soname changed, fixed a bug in the parsing code when dpkg send the same state more than once (at the end) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-25 * merged with apt@packages.debian.org/apt--main--0, added changelog entry for the 0.6.40.1 upload * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-26 * fix a bug when out-of-order states are send from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-27 * changelog update * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-28 * a real changelog entry now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-29 * changelog finalized * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-30 * propper (and sane) support for pmerror and pmconffile added
16 years ago
* merged from main Patches applied: * apt@packages.debian.org/apt--main--0--patch-106 Restore lost changelog entries * apt@packages.debian.org/apt--main--0--patch-107 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-108 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-109 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-110 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * michael.vogt@ubuntu.com--2005/apt--fixes--0--patch-5 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--base-0 tag of apt@packages.debian.org/apt--main--0--patch-85 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-1 * inital proof of concept code, understands what dpkg tells it already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-2 * progress reporting works now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-3 * added "APT::Status-Fd" variable * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-4 * do i18n now too * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-5 * define N_(x) if it is not defined already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-6 * PackageManager::DoInstall(int status_fd) added (does not break the ABI) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-7 * merged with apt--fixes--0 to make it build again * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-8 * added support for "error" and "conffile-prompt" messages from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-9 merge with main * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-10 * use sizeof() for all snprintf() uses; fix a potential line break problem in the status reading code; changed the N_() to _() calls * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-11 * added APT::KeepFDs configuration list for file descriptors that apt should leave open (needed for various frontends like debconf, synaptic) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-12 * fixed a API breakage * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-13 * doc added, should be releasable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-14 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-15 * more source comments, added Debug::DpkgPM debug code to inspect the dpkg<->apt communication, broke the abi (ok with matt) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-16 * the progress reporting has it's own "Debug::pkgDPkgProgressReporting" debug variable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-17 * merged PackageOps and TranslatedPackageOps into a single Map with the new DpkgState struct * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-18 * clear the APT::Keep-Fds configuration when it's no longer needed * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-19 * rewrote the reading from dpkg so that it never blocks * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-20 * merged the two status arrays into one * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-21 * added support for download progress reporting too (for Kamion and base-config) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-22 * ABI break; added Configuration::Clear(string List, {int,string} value) added (to remove a single Value from a list); test/conf_clear.cc added * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-23 * remvoed a debug string * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-24 * soname changed, fixed a bug in the parsing code when dpkg send the same state more than once (at the end) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-25 * merged with apt@packages.debian.org/apt--main--0, added changelog entry for the 0.6.40.1 upload * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-26 * fix a bug when out-of-order states are send from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-27 * changelog update * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-28 * a real changelog entry now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-29 * changelog finalized * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-30 * propper (and sane) support for pmerror and pmconffile added
16 years ago
* merged from main Patches applied: * apt@packages.debian.org/apt--main--0--patch-106 Restore lost changelog entries * apt@packages.debian.org/apt--main--0--patch-107 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-108 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-109 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-110 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * michael.vogt@ubuntu.com--2005/apt--fixes--0--patch-5 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--base-0 tag of apt@packages.debian.org/apt--main--0--patch-85 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-1 * inital proof of concept code, understands what dpkg tells it already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-2 * progress reporting works now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-3 * added "APT::Status-Fd" variable * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-4 * do i18n now too * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-5 * define N_(x) if it is not defined already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-6 * PackageManager::DoInstall(int status_fd) added (does not break the ABI) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-7 * merged with apt--fixes--0 to make it build again * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-8 * added support for "error" and "conffile-prompt" messages from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-9 merge with main * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-10 * use sizeof() for all snprintf() uses; fix a potential line break problem in the status reading code; changed the N_() to _() calls * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-11 * added APT::KeepFDs configuration list for file descriptors that apt should leave open (needed for various frontends like debconf, synaptic) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-12 * fixed a API breakage * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-13 * doc added, should be releasable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-14 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-15 * more source comments, added Debug::DpkgPM debug code to inspect the dpkg<->apt communication, broke the abi (ok with matt) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-16 * the progress reporting has it's own "Debug::pkgDPkgProgressReporting" debug variable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-17 * merged PackageOps and TranslatedPackageOps into a single Map with the new DpkgState struct * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-18 * clear the APT::Keep-Fds configuration when it's no longer needed * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-19 * rewrote the reading from dpkg so that it never blocks * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-20 * merged the two status arrays into one * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-21 * added support for download progress reporting too (for Kamion and base-config) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-22 * ABI break; added Configuration::Clear(string List, {int,string} value) added (to remove a single Value from a list); test/conf_clear.cc added * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-23 * remvoed a debug string * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-24 * soname changed, fixed a bug in the parsing code when dpkg send the same state more than once (at the end) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-25 * merged with apt@packages.debian.org/apt--main--0, added changelog entry for the 0.6.40.1 upload * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-26 * fix a bug when out-of-order states are send from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-27 * changelog update * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-28 * a real changelog entry now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-29 * changelog finalized * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-30 * propper (and sane) support for pmerror and pmconffile added
16 years ago
* merged from main Patches applied: * apt@packages.debian.org/apt--main--0--patch-106 Restore lost changelog entries * apt@packages.debian.org/apt--main--0--patch-107 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-108 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-109 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * apt@packages.debian.org/apt--main--0--patch-110 Merge michael.vogt@ubuntu.com--2005/apt--progress-reporting--0 * michael.vogt@ubuntu.com--2005/apt--fixes--0--patch-5 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--base-0 tag of apt@packages.debian.org/apt--main--0--patch-85 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-1 * inital proof of concept code, understands what dpkg tells it already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-2 * progress reporting works now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-3 * added "APT::Status-Fd" variable * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-4 * do i18n now too * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-5 * define N_(x) if it is not defined already * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-6 * PackageManager::DoInstall(int status_fd) added (does not break the ABI) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-7 * merged with apt--fixes--0 to make it build again * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-8 * added support for "error" and "conffile-prompt" messages from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-9 merge with main * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-10 * use sizeof() for all snprintf() uses; fix a potential line break problem in the status reading code; changed the N_() to _() calls * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-11 * added APT::KeepFDs configuration list for file descriptors that apt should leave open (needed for various frontends like debconf, synaptic) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-12 * fixed a API breakage * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-13 * doc added, should be releasable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-14 * merged with apt--main--0 * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-15 * more source comments, added Debug::DpkgPM debug code to inspect the dpkg<->apt communication, broke the abi (ok with matt) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-16 * the progress reporting has it's own "Debug::pkgDPkgProgressReporting" debug variable now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-17 * merged PackageOps and TranslatedPackageOps into a single Map with the new DpkgState struct * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-18 * clear the APT::Keep-Fds configuration when it's no longer needed * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-19 * rewrote the reading from dpkg so that it never blocks * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-20 * merged the two status arrays into one * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-21 * added support for download progress reporting too (for Kamion and base-config) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-22 * ABI break; added Configuration::Clear(string List, {int,string} value) added (to remove a single Value from a list); test/conf_clear.cc added * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-23 * remvoed a debug string * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-24 * soname changed, fixed a bug in the parsing code when dpkg send the same state more than once (at the end) * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-25 * merged with apt@packages.debian.org/apt--main--0, added changelog entry for the 0.6.40.1 upload * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-26 * fix a bug when out-of-order states are send from dpkg * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-27 * changelog update * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-28 * a real changelog entry now * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-29 * changelog finalized * michael.vogt@ubuntu.com--2005/apt--progress-reporting--0--patch-30 * propper (and sane) support for pmerror and pmconffile added
16 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire.cc,v 1.50 2004/03/17 05:17:11 mdz Exp $
  4. /* ######################################################################
  5. Acquire - File Acquiration
  6. The core element for the schedule system is the concept of a named
  7. queue. Each queue is unique and each queue has a name derived from the
  8. URI. The degree of paralization can be controlled by how the queue
  9. name is derived from the URI.
  10. ##################################################################### */
  11. /*}}}*/
  12. // Include Files /*{{{*/
  13. #include <config.h>
  14. #include <apt-pkg/acquire.h>
  15. #include <apt-pkg/acquire-item.h>
  16. #include <apt-pkg/acquire-worker.h>
  17. #include <apt-pkg/configuration.h>
  18. #include <apt-pkg/error.h>
  19. #include <apt-pkg/strutl.h>
  20. #include <apt-pkg/fileutl.h>
  21. #include <string>
  22. #include <vector>
  23. #include <iostream>
  24. #include <sstream>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #include <iomanip>
  30. #include <dirent.h>
  31. #include <sys/time.h>
  32. #include <sys/select.h>
  33. #include <errno.h>
  34. #include <apti18n.h>
  35. /*}}}*/
  36. using namespace std;
  37. // Acquire::pkgAcquire - Constructor /*{{{*/
  38. // ---------------------------------------------------------------------
  39. /* We grab some runtime state from the configuration space */
  40. pkgAcquire::pkgAcquire() : LockFD(-1), Queues(0), Workers(0), Configs(0), Log(NULL), ToFetch(0),
  41. Debug(_config->FindB("Debug::pkgAcquire",false)),
  42. Running(false)
  43. {
  44. string const Mode = _config->Find("Acquire::Queue-Mode","host");
  45. if (strcasecmp(Mode.c_str(),"host") == 0)
  46. QueueMode = QueueHost;
  47. if (strcasecmp(Mode.c_str(),"access") == 0)
  48. QueueMode = QueueAccess;
  49. }
  50. pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : LockFD(-1), Queues(0), Workers(0),
  51. Configs(0), Log(Progress), ToFetch(0),
  52. Debug(_config->FindB("Debug::pkgAcquire",false)),
  53. Running(false)
  54. {
  55. string const Mode = _config->Find("Acquire::Queue-Mode","host");
  56. if (strcasecmp(Mode.c_str(),"host") == 0)
  57. QueueMode = QueueHost;
  58. if (strcasecmp(Mode.c_str(),"access") == 0)
  59. QueueMode = QueueAccess;
  60. Setup(Progress, "");
  61. }
  62. /*}}}*/
  63. // Acquire::Setup - Delayed Constructor /*{{{*/
  64. // ---------------------------------------------------------------------
  65. /* Do everything needed to be a complete Acquire object and report the
  66. success (or failure) back so the user knows that something is wrong… */
  67. bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock,
  68. bool const createDirectories)
  69. {
  70. Log = Progress;
  71. // check for existence and possibly create auxiliary directories
  72. if (createDirectories == true)
  73. {
  74. string const listDir = _config->FindDir("Dir::State::lists");
  75. string const partialListDir = listDir + "partial/";
  76. string const archivesDir = _config->FindDir("Dir::Cache::Archives");
  77. string const partialArchivesDir = archivesDir + "partial/";
  78. if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false &&
  79. CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false)
  80. return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str());
  81. if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::Cache"), partialArchivesDir) == false &&
  82. CreateAPTDirectoryIfNeeded(archivesDir, partialArchivesDir) == false)
  83. return _error->Errno("Acquire", _("Archives directory %spartial is missing."), archivesDir.c_str());
  84. }
  85. if (Lock.empty() == true || _config->FindB("Debug::NoLocking", false) == true)
  86. return true;
  87. // Lock the directory this acquire object will work in
  88. LockFD = GetLock(flCombine(Lock, "lock"));
  89. if (LockFD == -1)
  90. return _error->Error(_("Unable to lock directory %s"), Lock.c_str());
  91. return true;
  92. }
  93. /*}}}*/
  94. // Acquire::~pkgAcquire - Destructor /*{{{*/
  95. // ---------------------------------------------------------------------
  96. /* Free our memory, clean up the queues (destroy the workers) */
  97. pkgAcquire::~pkgAcquire()
  98. {
  99. Shutdown();
  100. if (LockFD != -1)
  101. close(LockFD);
  102. while (Configs != 0)
  103. {
  104. MethodConfig *Jnk = Configs;
  105. Configs = Configs->Next;
  106. delete Jnk;
  107. }
  108. }
  109. /*}}}*/
  110. // Acquire::Shutdown - Clean out the acquire object /*{{{*/
  111. // ---------------------------------------------------------------------
  112. /* */
  113. void pkgAcquire::Shutdown()
  114. {
  115. while (Items.empty() == false)
  116. {
  117. if (Items[0]->Status == Item::StatFetching)
  118. Items[0]->Status = Item::StatError;
  119. delete Items[0];
  120. }
  121. while (Queues != 0)
  122. {
  123. Queue *Jnk = Queues;
  124. Queues = Queues->Next;
  125. delete Jnk;
  126. }
  127. }
  128. /*}}}*/
  129. // Acquire::Add - Add a new item /*{{{*/
  130. // ---------------------------------------------------------------------
  131. /* This puts an item on the acquire list. This list is mainly for tracking
  132. item status */
  133. void pkgAcquire::Add(Item *Itm)
  134. {
  135. Items.push_back(Itm);
  136. }
  137. /*}}}*/
  138. // Acquire::Remove - Remove a item /*{{{*/
  139. // ---------------------------------------------------------------------
  140. /* Remove an item from the acquire list. This is usually not used.. */
  141. void pkgAcquire::Remove(Item *Itm)
  142. {
  143. Dequeue(Itm);
  144. for (ItemIterator I = Items.begin(); I != Items.end();)
  145. {
  146. if (*I == Itm)
  147. {
  148. Items.erase(I);
  149. I = Items.begin();
  150. }
  151. else
  152. ++I;
  153. }
  154. }
  155. /*}}}*/
  156. // Acquire::Add - Add a worker /*{{{*/
  157. // ---------------------------------------------------------------------
  158. /* A list of workers is kept so that the select loop can direct their FD
  159. usage. */
  160. void pkgAcquire::Add(Worker *Work)
  161. {
  162. Work->NextAcquire = Workers;
  163. Workers = Work;
  164. }
  165. /*}}}*/
  166. // Acquire::Remove - Remove a worker /*{{{*/
  167. // ---------------------------------------------------------------------
  168. /* A worker has died. This can not be done while the select loop is running
  169. as it would require that RunFds could handling a changing list state and
  170. it can't.. */
  171. void pkgAcquire::Remove(Worker *Work)
  172. {
  173. if (Running == true)
  174. abort();
  175. Worker **I = &Workers;
  176. for (; *I != 0;)
  177. {
  178. if (*I == Work)
  179. *I = (*I)->NextAcquire;
  180. else
  181. I = &(*I)->NextAcquire;
  182. }
  183. }
  184. /*}}}*/
  185. // Acquire::Enqueue - Queue an URI for fetching /*{{{*/
  186. // ---------------------------------------------------------------------
  187. /* This is the entry point for an item. An item calls this function when
  188. it is constructed which creates a queue (based on the current queue
  189. mode) and puts the item in that queue. If the system is running then
  190. the queue might be started. */
  191. void pkgAcquire::Enqueue(ItemDesc &Item)
  192. {
  193. // Determine which queue to put the item in
  194. const MethodConfig *Config;
  195. string Name = QueueName(Item.URI,Config);
  196. if (Name.empty() == true)
  197. return;
  198. // Find the queue structure
  199. Queue *I = Queues;
  200. for (; I != 0 && I->Name != Name; I = I->Next);
  201. if (I == 0)
  202. {
  203. I = new Queue(Name,this);
  204. I->Next = Queues;
  205. Queues = I;
  206. if (Running == true)
  207. I->Startup();
  208. }
  209. // See if this is a local only URI
  210. if (Config->LocalOnly == true && Item.Owner->Complete == false)
  211. Item.Owner->Local = true;
  212. Item.Owner->Status = Item::StatIdle;
  213. // Queue it into the named queue
  214. if(I->Enqueue(Item))
  215. ToFetch++;
  216. // Some trace stuff
  217. if (Debug == true)
  218. {
  219. clog << "Fetching " << Item.URI << endl;
  220. clog << " to " << Item.Owner->DestFile << endl;
  221. clog << " Queue is: " << Name << endl;
  222. }
  223. }
  224. /*}}}*/
  225. // Acquire::Dequeue - Remove an item from all queues /*{{{*/
  226. // ---------------------------------------------------------------------
  227. /* This is called when an item is finished being fetched. It removes it
  228. from all the queues */
  229. void pkgAcquire::Dequeue(Item *Itm)
  230. {
  231. Queue *I = Queues;
  232. bool Res = false;
  233. if (Debug == true)
  234. clog << "Dequeuing " << Itm->DestFile << endl;
  235. for (; I != 0; I = I->Next)
  236. {
  237. if (I->Dequeue(Itm))
  238. {
  239. Res = true;
  240. if (Debug == true)
  241. clog << "Dequeued from " << I->Name << endl;
  242. }
  243. }
  244. if (Res == true)
  245. ToFetch--;
  246. }
  247. /*}}}*/
  248. // Acquire::QueueName - Return the name of the queue for this URI /*{{{*/
  249. // ---------------------------------------------------------------------
  250. /* The string returned depends on the configuration settings and the
  251. method parameters. Given something like http://foo.org/bar it can
  252. return http://foo.org or http */
  253. string pkgAcquire::QueueName(string Uri,MethodConfig const *&Config)
  254. {
  255. URI U(Uri);
  256. Config = GetConfig(U.Access);
  257. if (Config == 0)
  258. return string();
  259. /* Single-Instance methods get exactly one queue per URI. This is
  260. also used for the Access queue method */
  261. if (Config->SingleInstance == true || QueueMode == QueueAccess)
  262. return U.Access;
  263. string AccessSchema = U.Access + ':',
  264. FullQueueName = AccessSchema + U.Host;
  265. unsigned int Instances = 0, SchemaLength = AccessSchema.length();
  266. Queue *I = Queues;
  267. for (; I != 0; I = I->Next) {
  268. // if the queue already exists, re-use it
  269. if (I->Name == FullQueueName)
  270. return FullQueueName;
  271. if (I->Name.compare(0, SchemaLength, AccessSchema) == 0)
  272. Instances++;
  273. }
  274. if (Debug) {
  275. clog << "Found " << Instances << " instances of " << U.Access << endl;
  276. }
  277. if (Instances >= (unsigned int)_config->FindI("Acquire::QueueHost::Limit",10))
  278. return U.Access;
  279. return FullQueueName;
  280. }
  281. /*}}}*/
  282. // Acquire::GetConfig - Fetch the configuration information /*{{{*/
  283. // ---------------------------------------------------------------------
  284. /* This locates the configuration structure for an access method. If
  285. a config structure cannot be found a Worker will be created to
  286. retrieve it */
  287. pkgAcquire::MethodConfig *pkgAcquire::GetConfig(string Access)
  288. {
  289. // Search for an existing config
  290. MethodConfig *Conf;
  291. for (Conf = Configs; Conf != 0; Conf = Conf->Next)
  292. if (Conf->Access == Access)
  293. return Conf;
  294. // Create the new config class
  295. Conf = new MethodConfig;
  296. Conf->Access = Access;
  297. Conf->Next = Configs;
  298. Configs = Conf;
  299. // Create the worker to fetch the configuration
  300. Worker Work(Conf);
  301. if (Work.Start() == false)
  302. return 0;
  303. /* if a method uses DownloadLimit, we switch to SingleInstance mode */
  304. if(_config->FindI("Acquire::"+Access+"::Dl-Limit",0) > 0)
  305. Conf->SingleInstance = true;
  306. return Conf;
  307. }
  308. /*}}}*/
  309. // Acquire::SetFds - Deal with readable FDs /*{{{*/
  310. // ---------------------------------------------------------------------
  311. /* Collect FDs that have activity monitors into the fd sets */
  312. void pkgAcquire::SetFds(int &Fd,fd_set *RSet,fd_set *WSet)
  313. {
  314. for (Worker *I = Workers; I != 0; I = I->NextAcquire)
  315. {
  316. if (I->InReady == true && I->InFd >= 0)
  317. {
  318. if (Fd < I->InFd)
  319. Fd = I->InFd;
  320. FD_SET(I->InFd,RSet);
  321. }
  322. if (I->OutReady == true && I->OutFd >= 0)
  323. {
  324. if (Fd < I->OutFd)
  325. Fd = I->OutFd;
  326. FD_SET(I->OutFd,WSet);
  327. }
  328. }
  329. }
  330. /*}}}*/
  331. // Acquire::RunFds - Deal with active FDs /*{{{*/
  332. // ---------------------------------------------------------------------
  333. /* Dispatch active FDs over to the proper workers. It is very important
  334. that a worker never be erased while this is running! The queue class
  335. should never erase a worker except during shutdown processing. */
  336. void pkgAcquire::RunFds(fd_set *RSet,fd_set *WSet)
  337. {
  338. for (Worker *I = Workers; I != 0; I = I->NextAcquire)
  339. {
  340. if (I->InFd >= 0 && FD_ISSET(I->InFd,RSet) != 0)
  341. I->InFdReady();
  342. if (I->OutFd >= 0 && FD_ISSET(I->OutFd,WSet) != 0)
  343. I->OutFdReady();
  344. }
  345. }
  346. /*}}}*/
  347. // Acquire::Run - Run the fetch sequence /*{{{*/
  348. // ---------------------------------------------------------------------
  349. /* This runs the queues. It manages a select loop for all of the
  350. Worker tasks. The workers interact with the queues and items to
  351. manage the actual fetch. */
  352. pkgAcquire::RunResult pkgAcquire::Run(int PulseIntervall)
  353. {
  354. Running = true;
  355. for (Queue *I = Queues; I != 0; I = I->Next)
  356. I->Startup();
  357. if (Log != 0)
  358. Log->Start();
  359. bool WasCancelled = false;
  360. // Run till all things have been acquired
  361. struct timeval tv;
  362. tv.tv_sec = 0;
  363. tv.tv_usec = PulseIntervall;
  364. while (ToFetch > 0)
  365. {
  366. fd_set RFds;
  367. fd_set WFds;
  368. int Highest = 0;
  369. FD_ZERO(&RFds);
  370. FD_ZERO(&WFds);
  371. SetFds(Highest,&RFds,&WFds);
  372. int Res;
  373. do
  374. {
  375. Res = select(Highest+1,&RFds,&WFds,0,&tv);
  376. }
  377. while (Res < 0 && errno == EINTR);
  378. if (Res < 0)
  379. {
  380. _error->Errno("select","Select has failed");
  381. break;
  382. }
  383. RunFds(&RFds,&WFds);
  384. if (_error->PendingError() == true)
  385. break;
  386. // Timeout, notify the log class
  387. if (Res == 0 || (Log != 0 && Log->Update == true))
  388. {
  389. tv.tv_usec = PulseIntervall;
  390. for (Worker *I = Workers; I != 0; I = I->NextAcquire)
  391. I->Pulse();
  392. if (Log != 0 && Log->Pulse(this) == false)
  393. {
  394. WasCancelled = true;
  395. break;
  396. }
  397. }
  398. }
  399. if (Log != 0)
  400. Log->Stop();
  401. // Shut down the acquire bits
  402. Running = false;
  403. for (Queue *I = Queues; I != 0; I = I->Next)
  404. I->Shutdown(false);
  405. // Shut down the items
  406. for (ItemIterator I = Items.begin(); I != Items.end(); ++I)
  407. (*I)->Finished();
  408. if (_error->PendingError())
  409. return Failed;
  410. if (WasCancelled)
  411. return Cancelled;
  412. return Continue;
  413. }
  414. /*}}}*/
  415. // Acquire::Bump - Called when an item is dequeued /*{{{*/
  416. // ---------------------------------------------------------------------
  417. /* This routine bumps idle queues in hopes that they will be able to fetch
  418. the dequeued item */
  419. void pkgAcquire::Bump()
  420. {
  421. for (Queue *I = Queues; I != 0; I = I->Next)
  422. I->Bump();
  423. }
  424. /*}}}*/
  425. // Acquire::WorkerStep - Step to the next worker /*{{{*/
  426. // ---------------------------------------------------------------------
  427. /* Not inlined to advoid including acquire-worker.h */
  428. pkgAcquire::Worker *pkgAcquire::WorkerStep(Worker *I)
  429. {
  430. return I->NextAcquire;
  431. }
  432. /*}}}*/
  433. // Acquire::Clean - Cleans a directory /*{{{*/
  434. // ---------------------------------------------------------------------
  435. /* This is a bit simplistic, it looks at every file in the dir and sees
  436. if it is part of the download set. */
  437. bool pkgAcquire::Clean(string Dir)
  438. {
  439. // non-existing directories are by definition clean…
  440. if (DirectoryExists(Dir) == false)
  441. return true;
  442. if(Dir == "/")
  443. return _error->Error(_("Clean of %s is not supported"), Dir.c_str());
  444. DIR *D = opendir(Dir.c_str());
  445. if (D == 0)
  446. return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
  447. string StartDir = SafeGetCWD();
  448. if (chdir(Dir.c_str()) != 0)
  449. {
  450. closedir(D);
  451. return _error->Errno("chdir",_("Unable to change to %s"),Dir.c_str());
  452. }
  453. for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D))
  454. {
  455. // Skip some files..
  456. if (strcmp(Dir->d_name,"lock") == 0 ||
  457. strcmp(Dir->d_name,"partial") == 0 ||
  458. strcmp(Dir->d_name,".") == 0 ||
  459. strcmp(Dir->d_name,"..") == 0)
  460. continue;
  461. // Look in the get list
  462. ItemCIterator I = Items.begin();
  463. for (; I != Items.end(); ++I)
  464. if (flNotDir((*I)->DestFile) == Dir->d_name)
  465. break;
  466. // Nothing found, nuke it
  467. if (I == Items.end())
  468. unlink(Dir->d_name);
  469. };
  470. closedir(D);
  471. if (chdir(StartDir.c_str()) != 0)
  472. return _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str());
  473. return true;
  474. }
  475. /*}}}*/
  476. // Acquire::TotalNeeded - Number of bytes to fetch /*{{{*/
  477. // ---------------------------------------------------------------------
  478. /* This is the total number of bytes needed */
  479. APT_PURE unsigned long long pkgAcquire::TotalNeeded()
  480. {
  481. unsigned long long Total = 0;
  482. for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I)
  483. Total += (*I)->FileSize;
  484. return Total;
  485. }
  486. /*}}}*/
  487. // Acquire::FetchNeeded - Number of bytes needed to get /*{{{*/
  488. // ---------------------------------------------------------------------
  489. /* This is the number of bytes that is not local */
  490. APT_PURE unsigned long long pkgAcquire::FetchNeeded()
  491. {
  492. unsigned long long Total = 0;
  493. for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I)
  494. if ((*I)->Local == false)
  495. Total += (*I)->FileSize;
  496. return Total;
  497. }
  498. /*}}}*/
  499. // Acquire::PartialPresent - Number of partial bytes we already have /*{{{*/
  500. // ---------------------------------------------------------------------
  501. /* This is the number of bytes that is not local */
  502. APT_PURE unsigned long long pkgAcquire::PartialPresent()
  503. {
  504. unsigned long long Total = 0;
  505. for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); ++I)
  506. if ((*I)->Local == false)
  507. Total += (*I)->PartialSize;
  508. return Total;
  509. }
  510. /*}}}*/
  511. // Acquire::UriBegin - Start iterator for the uri list /*{{{*/
  512. // ---------------------------------------------------------------------
  513. /* */
  514. pkgAcquire::UriIterator pkgAcquire::UriBegin()
  515. {
  516. return UriIterator(Queues);
  517. }
  518. /*}}}*/
  519. // Acquire::UriEnd - End iterator for the uri list /*{{{*/
  520. // ---------------------------------------------------------------------
  521. /* */
  522. pkgAcquire::UriIterator pkgAcquire::UriEnd()
  523. {
  524. return UriIterator(0);
  525. }
  526. /*}}}*/
  527. // Acquire::MethodConfig::MethodConfig - Constructor /*{{{*/
  528. // ---------------------------------------------------------------------
  529. /* */
  530. pkgAcquire::MethodConfig::MethodConfig() : d(NULL), Next(0), SingleInstance(false),
  531. Pipeline(false), SendConfig(false), LocalOnly(false), NeedsCleanup(false),
  532. Removable(false)
  533. {
  534. }
  535. /*}}}*/
  536. // Queue::Queue - Constructor /*{{{*/
  537. // ---------------------------------------------------------------------
  538. /* */
  539. pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : d(NULL), Next(0),
  540. Name(Name), Items(0), Workers(0), Owner(Owner), PipeDepth(0), MaxPipeDepth(1)
  541. {
  542. }
  543. /*}}}*/
  544. // Queue::~Queue - Destructor /*{{{*/
  545. // ---------------------------------------------------------------------
  546. /* */
  547. pkgAcquire::Queue::~Queue()
  548. {
  549. Shutdown(true);
  550. while (Items != 0)
  551. {
  552. QItem *Jnk = Items;
  553. Items = Items->Next;
  554. delete Jnk;
  555. }
  556. }
  557. /*}}}*/
  558. // Queue::Enqueue - Queue an item to the queue /*{{{*/
  559. // ---------------------------------------------------------------------
  560. /* */
  561. bool pkgAcquire::Queue::Enqueue(ItemDesc &Item)
  562. {
  563. QItem **I = &Items;
  564. // move to the end of the queue and check for duplicates here
  565. for (; *I != 0; I = &(*I)->Next)
  566. if (Item.URI == (*I)->URI)
  567. {
  568. Item.Owner->Status = Item::StatDone;
  569. return false;
  570. }
  571. // Create a new item
  572. QItem *Itm = new QItem;
  573. *Itm = Item;
  574. Itm->Next = 0;
  575. *I = Itm;
  576. Item.Owner->QueueCounter++;
  577. if (Items->Next == 0)
  578. Cycle();
  579. return true;
  580. }
  581. /*}}}*/
  582. // Queue::Dequeue - Remove an item from the queue /*{{{*/
  583. // ---------------------------------------------------------------------
  584. /* We return true if we hit something */
  585. bool pkgAcquire::Queue::Dequeue(Item *Owner)
  586. {
  587. if (Owner->Status == pkgAcquire::Item::StatFetching)
  588. return _error->Error("Tried to dequeue a fetching object");
  589. bool Res = false;
  590. QItem **I = &Items;
  591. for (; *I != 0;)
  592. {
  593. if ((*I)->Owner == Owner)
  594. {
  595. QItem *Jnk= *I;
  596. *I = (*I)->Next;
  597. Owner->QueueCounter--;
  598. delete Jnk;
  599. Res = true;
  600. }
  601. else
  602. I = &(*I)->Next;
  603. }
  604. return Res;
  605. }
  606. /*}}}*/
  607. // Queue::Startup - Start the worker processes /*{{{*/
  608. // ---------------------------------------------------------------------
  609. /* It is possible for this to be called with a pre-existing set of
  610. workers. */
  611. bool pkgAcquire::Queue::Startup()
  612. {
  613. if (Workers == 0)
  614. {
  615. URI U(Name);
  616. pkgAcquire::MethodConfig *Cnf = Owner->GetConfig(U.Access);
  617. if (Cnf == 0)
  618. return false;
  619. Workers = new Worker(this,Cnf,Owner->Log);
  620. Owner->Add(Workers);
  621. if (Workers->Start() == false)
  622. return false;
  623. /* When pipelining we commit 10 items. This needs to change when we
  624. added other source retry to have cycle maintain a pipeline depth
  625. on its own. */
  626. if (Cnf->Pipeline == true)
  627. MaxPipeDepth = _config->FindI("Acquire::Max-Pipeline-Depth",10);
  628. else
  629. MaxPipeDepth = 1;
  630. }
  631. return Cycle();
  632. }
  633. /*}}}*/
  634. // Queue::Shutdown - Shutdown the worker processes /*{{{*/
  635. // ---------------------------------------------------------------------
  636. /* If final is true then all workers are eliminated, otherwise only workers
  637. that do not need cleanup are removed */
  638. bool pkgAcquire::Queue::Shutdown(bool Final)
  639. {
  640. // Delete all of the workers
  641. pkgAcquire::Worker **Cur = &Workers;
  642. while (*Cur != 0)
  643. {
  644. pkgAcquire::Worker *Jnk = *Cur;
  645. if (Final == true || Jnk->GetConf()->NeedsCleanup == false)
  646. {
  647. *Cur = Jnk->NextQueue;
  648. Owner->Remove(Jnk);
  649. delete Jnk;
  650. }
  651. else
  652. Cur = &(*Cur)->NextQueue;
  653. }
  654. return true;
  655. }
  656. /*}}}*/
  657. // Queue::FindItem - Find a URI in the item list /*{{{*/
  658. // ---------------------------------------------------------------------
  659. /* */
  660. pkgAcquire::Queue::QItem *pkgAcquire::Queue::FindItem(string URI,pkgAcquire::Worker *Owner)
  661. {
  662. for (QItem *I = Items; I != 0; I = I->Next)
  663. if (I->URI == URI && I->Worker == Owner)
  664. return I;
  665. return 0;
  666. }
  667. /*}}}*/
  668. // Queue::ItemDone - Item has been completed /*{{{*/
  669. // ---------------------------------------------------------------------
  670. /* The worker signals this which causes the item to be removed from the
  671. queue. If this is the last queue instance then it is removed from the
  672. main queue too.*/
  673. bool pkgAcquire::Queue::ItemDone(QItem *Itm)
  674. {
  675. PipeDepth--;
  676. if (Itm->Owner->Status == pkgAcquire::Item::StatFetching)
  677. Itm->Owner->Status = pkgAcquire::Item::StatDone;
  678. if (Itm->Owner->QueueCounter <= 1)
  679. Owner->Dequeue(Itm->Owner);
  680. else
  681. {
  682. Dequeue(Itm->Owner);
  683. Owner->Bump();
  684. }
  685. return Cycle();
  686. }
  687. /*}}}*/
  688. // Queue::Cycle - Queue new items into the method /*{{{*/
  689. // ---------------------------------------------------------------------
  690. /* This locates a new idle item and sends it to the worker. If pipelining
  691. is enabled then it keeps the pipe full. */
  692. bool pkgAcquire::Queue::Cycle()
  693. {
  694. if (Items == 0 || Workers == 0)
  695. return true;
  696. if (PipeDepth < 0)
  697. return _error->Error("Pipedepth failure");
  698. // Look for a queable item
  699. QItem *I = Items;
  700. while (PipeDepth < (signed)MaxPipeDepth)
  701. {
  702. for (; I != 0; I = I->Next)
  703. if (I->Owner->Status == pkgAcquire::Item::StatIdle)
  704. break;
  705. // Nothing to do, queue is idle.
  706. if (I == 0)
  707. return true;
  708. I->Worker = Workers;
  709. I->Owner->Status = pkgAcquire::Item::StatFetching;
  710. PipeDepth++;
  711. if (Workers->QueueItem(I) == false)
  712. return false;
  713. }
  714. return true;
  715. }
  716. /*}}}*/
  717. // Queue::Bump - Fetch any pending objects if we are idle /*{{{*/
  718. // ---------------------------------------------------------------------
  719. /* This is called when an item in multiple queues is dequeued */
  720. void pkgAcquire::Queue::Bump()
  721. {
  722. Cycle();
  723. }
  724. /*}}}*/
  725. // AcquireStatus::pkgAcquireStatus - Constructor /*{{{*/
  726. // ---------------------------------------------------------------------
  727. /* */
  728. pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Percent(0), Update(true), MorePulses(false)
  729. {
  730. Start();
  731. }
  732. /*}}}*/
  733. // AcquireStatus::Pulse - Called periodically /*{{{*/
  734. // ---------------------------------------------------------------------
  735. /* This computes some internal state variables for the derived classes to
  736. use. It generates the current downloaded bytes and total bytes to download
  737. as well as the current CPS estimate. */
  738. bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
  739. {
  740. TotalBytes = 0;
  741. CurrentBytes = 0;
  742. TotalItems = 0;
  743. CurrentItems = 0;
  744. // Compute the total number of bytes to fetch
  745. unsigned int Unknown = 0;
  746. unsigned int Count = 0;
  747. bool UnfetchedReleaseFiles = false;
  748. for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin();
  749. I != Owner->ItemsEnd();
  750. ++I, ++Count)
  751. {
  752. TotalItems++;
  753. if ((*I)->Status == pkgAcquire::Item::StatDone)
  754. ++CurrentItems;
  755. // Totally ignore local items
  756. if ((*I)->Local == true)
  757. continue;
  758. // see if the method tells us to expect more
  759. TotalItems += (*I)->ExpectedAdditionalItems;
  760. // check if there are unfetched Release files
  761. if ((*I)->Complete == false && (*I)->ExpectedAdditionalItems > 0)
  762. UnfetchedReleaseFiles = true;
  763. TotalBytes += (*I)->FileSize;
  764. if ((*I)->Complete == true)
  765. CurrentBytes += (*I)->FileSize;
  766. if ((*I)->FileSize == 0 && (*I)->Complete == false)
  767. ++Unknown;
  768. }
  769. // Compute the current completion
  770. unsigned long long ResumeSize = 0;
  771. for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0;
  772. I = Owner->WorkerStep(I))
  773. {
  774. if (I->CurrentItem != 0 && I->CurrentItem->Owner->Complete == false)
  775. {
  776. CurrentBytes += I->CurrentSize;
  777. ResumeSize += I->ResumePoint;
  778. // Files with unknown size always have 100% completion
  779. if (I->CurrentItem->Owner->FileSize == 0 &&
  780. I->CurrentItem->Owner->Complete == false)
  781. TotalBytes += I->CurrentSize;
  782. }
  783. }
  784. // Normalize the figures and account for unknown size downloads
  785. if (TotalBytes <= 0)
  786. TotalBytes = 1;
  787. if (Unknown == Count)
  788. TotalBytes = Unknown;
  789. // Wha?! Is not supposed to happen.
  790. if (CurrentBytes > TotalBytes)
  791. CurrentBytes = TotalBytes;
  792. // debug
  793. if (_config->FindB("Debug::acquire::progress", false) == true)
  794. std::clog << " Bytes: "
  795. << SizeToStr(CurrentBytes) << " / " << SizeToStr(TotalBytes)
  796. << std::endl;
  797. // Compute the CPS
  798. struct timeval NewTime;
  799. gettimeofday(&NewTime,0);
  800. if ((NewTime.tv_sec - Time.tv_sec == 6 && NewTime.tv_usec > Time.tv_usec) ||
  801. NewTime.tv_sec - Time.tv_sec > 6)
  802. {
  803. double Delta = NewTime.tv_sec - Time.tv_sec +
  804. (NewTime.tv_usec - Time.tv_usec)/1000000.0;
  805. // Compute the CPS value
  806. if (Delta < 0.01)
  807. CurrentCPS = 0;
  808. else
  809. CurrentCPS = ((CurrentBytes - ResumeSize) - LastBytes)/Delta;
  810. LastBytes = CurrentBytes - ResumeSize;
  811. ElapsedTime = (unsigned long long)Delta;
  812. Time = NewTime;
  813. }
  814. // calculate the percentage, if we have too little data assume 1%
  815. if (TotalBytes > 0 && UnfetchedReleaseFiles)
  816. Percent = 0;
  817. else
  818. // use both files and bytes because bytes can be unreliable
  819. Percent = (0.8 * (CurrentBytes/float(TotalBytes)*100.0) +
  820. 0.2 * (CurrentItems/float(TotalItems)*100.0));
  821. int fd = _config->FindI("APT::Status-Fd",-1);
  822. if(fd > 0)
  823. {
  824. ostringstream status;
  825. char msg[200];
  826. long i = CurrentItems < TotalItems ? CurrentItems + 1 : CurrentItems;
  827. unsigned long long ETA = 0;
  828. if(CurrentCPS > 0)
  829. ETA = (TotalBytes - CurrentBytes) / CurrentCPS;
  830. // only show the ETA if it makes sense
  831. if (ETA > 0 && ETA < 172800 /* two days */ )
  832. snprintf(msg,sizeof(msg), _("Retrieving file %li of %li (%s remaining)"), i, TotalItems, TimeToStr(ETA).c_str());
  833. else
  834. snprintf(msg,sizeof(msg), _("Retrieving file %li of %li"), i, TotalItems);
  835. // build the status str
  836. status << "dlstatus:" << i
  837. << ":" << std::setprecision(3) << Percent
  838. << ":" << msg
  839. << endl;
  840. std::string const dlstatus = status.str();
  841. FileFd::Write(fd, dlstatus.c_str(), dlstatus.size());
  842. }
  843. return true;
  844. }
  845. /*}}}*/
  846. // AcquireStatus::Start - Called when the download is started /*{{{*/
  847. // ---------------------------------------------------------------------
  848. /* We just reset the counters */
  849. void pkgAcquireStatus::Start()
  850. {
  851. gettimeofday(&Time,0);
  852. gettimeofday(&StartTime,0);
  853. LastBytes = 0;
  854. CurrentCPS = 0;
  855. CurrentBytes = 0;
  856. TotalBytes = 0;
  857. FetchedBytes = 0;
  858. ElapsedTime = 0;
  859. TotalItems = 0;
  860. CurrentItems = 0;
  861. }
  862. /*}}}*/
  863. // AcquireStatus::Stop - Finished downloading /*{{{*/
  864. // ---------------------------------------------------------------------
  865. /* This accurately computes the elapsed time and the total overall CPS. */
  866. void pkgAcquireStatus::Stop()
  867. {
  868. // Compute the CPS and elapsed time
  869. struct timeval NewTime;
  870. gettimeofday(&NewTime,0);
  871. double Delta = NewTime.tv_sec - StartTime.tv_sec +
  872. (NewTime.tv_usec - StartTime.tv_usec)/1000000.0;
  873. // Compute the CPS value
  874. if (Delta < 0.01)
  875. CurrentCPS = 0;
  876. else
  877. CurrentCPS = FetchedBytes/Delta;
  878. LastBytes = CurrentBytes;
  879. ElapsedTime = (unsigned long long)Delta;
  880. }
  881. /*}}}*/
  882. // AcquireStatus::Fetched - Called when a byte set has been fetched /*{{{*/
  883. // ---------------------------------------------------------------------
  884. /* This is used to get accurate final transfer rate reporting. */
  885. void pkgAcquireStatus::Fetched(unsigned long long Size,unsigned long long Resume)
  886. {
  887. FetchedBytes += Size - Resume;
  888. }
  889. /*}}}*/