From eb9f6c23f7a3b4554531b3b8da2b5b05e0fe1da7 Mon Sep 17 00:00:00 2001 From: Daniel Hartwig Date: Fri, 11 May 2012 15:54:19 +0800 Subject: [PATCH] Support really big files in the download system This follows recent changes in apt which added support for files greater than several gigabytes in size -- using the 'unsigned long long' type to store the file size. Changelog download is restored as a result of this. Closes: #669569 LP: #824708 --- NEWS | 20 +++++++++++ src/cmdline/cmdline_changelog.cc | 8 ++-- src/cmdline/cmdline_download_progress_display.cc | 32 +++++++++--------- src/cmdline/cmdline_prompt.cc | 2 +- src/download_list.cc | 17 +++++---- src/download_list.h | 8 ++-- src/download_thread.cc | 4 +- src/download_thread.h | 2 +- src/generic/apt/aptcache.h | 4 +- src/generic/apt/download_queue.cc | 6 ++-- src/generic/apt/download_queue.h | 4 +- src/generic/apt/download_signal_log.cc | 2 +- src/generic/apt/download_signal_log.h | 16 ++++---- src/generic/apt/pkg_changelog.cc | 4 +- .../controllers/acquire_download_progress.cc | 16 ++++---- src/generic/views/download_progress.h | 36 ++++++++++---------- src/generic/views/mocks/download_progress.h | 4 +- src/view_changelog.cc | 4 +- tests/test_cmdline_download_status_display.cc | 12 ------ 19 files changed, 105 insertions(+), 96 deletions(-) diff --git a/NEWS b/NEWS index 5742cf5..23908ef 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,23 @@ +[5/11/2012] +Version 0.6.8 "Never need a reason, + never need a rhyme" + +This version of aptitude requires apt 0.9 and will not build against +earlier releases. + +- New features: + + * [all]: Support really big files in the download system + + This follows recent changes in apt which added support for + files greater than several gigabytes in size -- using the + 'unsigned long long' type to store the file size. + +- Minor bugs: + + * [all]: Changelog downloading is restored + (Closes: #669569, LP: #824708) + [5/2/2012] Version 0.6.7 "I said 'Step pause turn pause pivot step step'" diff --git a/src/cmdline/cmdline_changelog.cc b/src/cmdline/cmdline_changelog.cc index 3dd7036..a2ea9e9 100644 --- a/src/cmdline/cmdline_changelog.cc +++ b/src/cmdline/cmdline_changelog.cc @@ -88,8 +88,8 @@ void set_name(temp::name n, temp::name *target) } void partial_download(const temp::name &name, - unsigned long currentSize, - unsigned long totalSize) + unsigned long long currentSize, + unsigned long long totalSize) { // Hack: ripped this code from AcqTextStatus. @@ -98,8 +98,8 @@ void set_name(temp::name n, temp::name *target) const int screen_width = term_metrics->get_screen_width(); - unsigned long TotalBytes = totalSize; - unsigned long CurrentBytes = currentSize; + unsigned long long TotalBytes = totalSize; + unsigned long long CurrentBytes = currentSize; std::ostringstream bufferStream; diff --git a/src/cmdline/cmdline_download_progress_display.cc b/src/cmdline/cmdline_download_progress_display.cc index 1588af9..e4c94f1 100644 --- a/src/cmdline/cmdline_download_progress_display.cc +++ b/src/cmdline/cmdline_download_progress_display.cc @@ -88,17 +88,17 @@ namespace aptitude void file_finished(const std::string &description, const boost::optional &id); - void done(double fetched_bytes, - unsigned long elapsed_time, - double latest_download_rate); + void done(unsigned long long fetched_bytes, + unsigned long long elapsed_time, + unsigned long long latest_download_rate); void media_change(const std::string &media, const std::string &drive, const sigc::slot1 &k); - virtual void complete(double fetched_bytes, - unsigned long elapsed_time, - double latest_download_rate); + virtual void complete(unsigned long long fetched_bytes, + unsigned long long elapsed_time, + unsigned long long latest_download_rate); }; download_progress::download_progress(bool _display_messages, @@ -199,9 +199,9 @@ namespace aptitude { } - void download_progress::done(double fetched_bytes, - unsigned long elapsed_time, - double latest_download_rate) + void download_progress::done(unsigned long long fetched_bytes, + unsigned long long elapsed_time, + unsigned long long latest_download_rate) { if(display_messages) { @@ -244,9 +244,9 @@ namespace aptitude k(true); } - void download_progress::complete(double fetched_bytes, - unsigned long elapsed_time, - double latest_download_rate) + void download_progress::complete(unsigned long long fetched_bytes, + unsigned long long elapsed_time, + unsigned long long latest_download_rate) { } @@ -332,8 +332,8 @@ namespace aptitude void operator()(const file_progress &progress) const { - const unsigned long current_size = progress.get_current_size(); - const unsigned long total_size = progress.get_total_size(); + const unsigned long long current_size = progress.get_current_size(); + const unsigned long long total_size = progress.get_total_size(); const bool complete = progress.get_complete(); const std::string &description = progress.get_description(); @@ -420,11 +420,11 @@ namespace aptitude void download_status_display_impl::display_status(const download_progress::status &status) { typedef views::download_progress::status::worker_status worker_status; - const double download_rate = status.get_download_rate(); + const unsigned long long download_rate = status.get_download_rate(); const std::vector &active_downloads = status.get_active_downloads(); const double fraction_complete = status.get_fraction_complete(); - const unsigned long time_remaining = status.get_time_remaining(); + const unsigned long long time_remaining = status.get_time_remaining(); const int percent = as_percent(fraction_complete); diff --git a/src/cmdline/cmdline_prompt.cc b/src/cmdline/cmdline_prompt.cc index c65f779..25fadaa 100644 --- a/src/cmdline/cmdline_prompt.cc +++ b/src/cmdline/cmdline_prompt.cc @@ -66,7 +66,7 @@ using boost::shared_ptr; struct fetchinfo { - double FetchBytes, FetchPBytes, DebBytes; + unsigned long long FetchBytes, FetchPBytes, DebBytes; fetchinfo() : FetchBytes(0), FetchPBytes(0), DebBytes(0) diff --git a/src/download_list.cc b/src/download_list.cc index 876aed8..9015165 100644 --- a/src/download_list.cc +++ b/src/download_list.cc @@ -58,12 +58,12 @@ namespace cwidget */ const int download_list_spinner_interval = 1; -download_list::workerinf::workerinf(const wstring &_msg, unsigned long _current, unsigned long _total) +download_list::workerinf::workerinf(const wstring &_msg, unsigned long long _current, unsigned long long _total) :msg(_msg), current(_current), total(_total) { } -download_list::workerinf::workerinf(const string &_msg, unsigned long _current, unsigned long _total) +download_list::workerinf::workerinf(const string &_msg, unsigned long long _current, unsigned long long _total) :msg(cw::util::transcode(_msg)), current(_current), total(_total) { } @@ -73,9 +73,9 @@ static cw::widget_ref download_summary(const download_list_ref &l, bool failed, bool already_cancelled, const sigc::slot0 &cancel_slot, - double FetchedBytes, - unsigned long ElapsedTime, - double CurrentCPS) + unsigned long long FetchedBytes, + unsigned long long ElapsedTime, + unsigned long long CurrentCPS) { vector fragments; @@ -221,12 +221,13 @@ void download_list::paint(const cw::style &st) if(display_cumulative_progress) { - unsigned long ETA = 0; + unsigned long long ETA = 0; if(CurrentCPS > 0) - ETA=(unsigned long)((TotalBytes-CurrentBytes)/CurrentCPS); + ETA = (TotalBytes - CurrentBytes) / CurrentCPS; - double fraction_complete = (double(CurrentBytes + CurrentItems))/(TotalBytes + TotalItems); + double fraction_complete = + ((double) (CurrentBytes + CurrentItems)) / ((double) (TotalBytes + TotalItems)); // Clamp to [0,1] if(fraction_complete > 1) diff --git a/src/download_list.h b/src/download_list.h index e8520dc..1ce8863 100644 --- a/src/download_list.h +++ b/src/download_list.h @@ -48,10 +48,10 @@ class download_list:public cwidget::widgets::widget struct workerinf { std::wstring msg; - unsigned long current, total; + unsigned long long current, total; - workerinf(const std::wstring &_msg, unsigned long _current, unsigned long _total); - workerinf(const std::string &_msg, unsigned long _current, unsigned long _total); + workerinf(const std::wstring &_msg, unsigned long long _current, unsigned long long _total); + workerinf(const std::string &_msg, unsigned long long _current, unsigned long long _total); }; typedef std::pair msg; @@ -100,7 +100,7 @@ class download_list:public cwidget::widgets::widget // We have to mirror the download_signal_log's information, since // we're only synchronous with it in the log callbacks. unsigned long TotalItems, CurrentItems; - double CurrentCPS, TotalBytes, CurrentBytes; + unsigned long long CurrentCPS, TotalBytes, CurrentBytes; /** \brief When the download started, as returned by time(2). * diff --git a/src/download_thread.cc b/src/download_thread.cc index 7fa2205..0c660e2 100644 --- a/src/download_thread.cc +++ b/src/download_thread.cc @@ -132,8 +132,8 @@ RVal do_foreground_execute(C *inst, return return_box.take(); } -void background_status::Fetched(unsigned long Size, - unsigned long ResumePoint) +void background_status::Fetched(unsigned long long Size, + unsigned long long ResumePoint) { do_foreground_execute(real_status, Size, ResumePoint, &download_signal_log::Fetched, diff --git a/src/download_thread.h b/src/download_thread.h index 1159e29..6fc431e 100644 --- a/src/download_thread.h +++ b/src/download_thread.h @@ -61,7 +61,7 @@ class background_status : public pkgAcquireStatus post_thunk_func post_thunk; public: - void Fetched(unsigned long Size, unsigned long ResumePoint); + void Fetched(unsigned long long Size, unsigned long long ResumePoint); bool MediaChange(std::string Media, std::string Drive); void IMSHit(pkgAcquire::ItemDesc &); void Fetch(pkgAcquire::ItemDesc &); diff --git a/src/generic/apt/aptcache.h b/src/generic/apt/aptcache.h index 3cbca96..df2857e 100644 --- a/src/generic/apt/aptcache.h +++ b/src/generic/apt/aptcache.h @@ -224,8 +224,8 @@ public: StateCache *PkgState; unsigned char *DepState; aptitude_state *AptitudeState; - double iUsrSize; - double iDownloadSize; + signed long long iUsrSize; + unsigned long long iDownloadSize; unsigned long iInstCount; unsigned long iDelCount; unsigned long iKeepCount; diff --git a/src/generic/apt/download_queue.cc b/src/generic/apt/download_queue.cc index 0c0b184..3efce49 100644 --- a/src/generic/apt/download_queue.cc +++ b/src/generic/apt/download_queue.cc @@ -153,8 +153,8 @@ namespace aptitude /** \brief Invoke the partial download callback on each listener. */ void invoke_partial_download(const temp::name &filename, - unsigned long currentSize, - unsigned long totalSize) const + unsigned long long currentSize, + unsigned long long totalSize) const { for(std::list::const_iterator it = listeners.begin(); it != listeners.end(); ++it) @@ -284,7 +284,7 @@ namespace aptitude } void Done(std::string Message, - unsigned long Size, + unsigned long long Size, std::string CalcHash, pkgAcquire::MethodConfig *Cnf) { diff --git a/src/generic/apt/download_queue.h b/src/generic/apt/download_queue.h index f734f8b..315563b 100644 --- a/src/generic/apt/download_queue.h +++ b/src/generic/apt/download_queue.h @@ -71,8 +71,8 @@ namespace aptitude * The default implementation does nothing. */ virtual void partial_download(const temp::name &filename, - unsigned long currentSize, - unsigned long totalSize) + unsigned long long currentSize, + unsigned long long totalSize) { } diff --git a/src/generic/apt/download_signal_log.cc b/src/generic/apt/download_signal_log.cc index 1f1c962..ef9dd99 100644 --- a/src/generic/apt/download_signal_log.cc +++ b/src/generic/apt/download_signal_log.cc @@ -40,7 +40,7 @@ static void set_bool(bool val, int *out) *out = val ? 1 : 0; } -void download_signal_log::Fetched(unsigned long Size, unsigned long ResumePoint) +void download_signal_log::Fetched(unsigned long long Size, unsigned long long ResumePoint) { pkgAcquireStatus::Fetched(Size, ResumePoint); diff --git a/src/generic/apt/download_signal_log.h b/src/generic/apt/download_signal_log.h index a48edff..a14ac81 100644 --- a/src/generic/apt/download_signal_log.h +++ b/src/generic/apt/download_signal_log.h @@ -66,18 +66,18 @@ public: struct timeval &get_time() {return Time;} struct timeval &get_start_time() {return StartTime;} - double get_last_bytes() {return LastBytes;} - double get_currentCPS() {return CurrentCPS;} - double get_current_bytes() {return CurrentBytes;} - double get_total_bytes() {return TotalBytes;} - double get_fetched_bytes() {return FetchedBytes;} - unsigned long get_elapsed_time() {return ElapsedTime;} + unsigned long long get_last_bytes() {return LastBytes;} + unsigned long long get_currentCPS() {return CurrentCPS;} + unsigned long long get_current_bytes() {return CurrentBytes;} + unsigned long long get_total_bytes() {return TotalBytes;} + unsigned long long get_fetched_bytes() {return FetchedBytes;} + unsigned long long get_elapsed_time() {return ElapsedTime;} unsigned long get_total_items() {return TotalItems;} unsigned long get_current_items() {return CurrentItems;} void set_update(bool _Update) {Update=_Update;} - sigc::signal3 Fetched_sig; sigc::signal4 &> MediaChange_sig; @@ -92,7 +92,7 @@ public: const sigc::slot0 &> Stop_sig; sigc::signal1 Complete_sig; - void Fetched(unsigned long Size, unsigned long ResumePoint); + void Fetched(unsigned long long Size, unsigned long long ResumePoint); void MediaChange(const std::string &Media, const std::string &Drive, const sigc::slot1 &k); bool MediaChange(std::string Media, std::string Drive); diff --git a/src/generic/apt/pkg_changelog.cc b/src/generic/apt/pkg_changelog.cc index 5f17c75..8724d24 100644 --- a/src/generic/apt/pkg_changelog.cc +++ b/src/generic/apt/pkg_changelog.cc @@ -305,8 +305,8 @@ namespace aptitude } void partial_download(const temp::name &filename, - unsigned long currentSize, - unsigned long totalSize) + unsigned long long currentSize, + unsigned long long totalSize) { parent->partial_download(filename, currentSize, totalSize); } diff --git a/src/generic/controllers/acquire_download_progress.cc b/src/generic/controllers/acquire_download_progress.cc index 8bc9687..12f8d0f 100644 --- a/src/generic/controllers/acquire_download_progress.cc +++ b/src/generic/controllers/acquire_download_progress.cc @@ -165,20 +165,20 @@ namespace aptitude } } - const double download_rate = manager.get_currentCPS(); + const unsigned long long download_rate = manager.get_currentCPS(); - const double current_bytes = manager.get_current_bytes(); - const double current_items = manager.get_current_items(); - const double total_bytes = manager.get_total_bytes(); - const double total_items = manager.get_total_items(); + const unsigned long long current_bytes = manager.get_current_bytes(); + const unsigned long long total_bytes = manager.get_total_bytes(); + const unsigned long current_items = manager.get_current_items(); + const unsigned long total_items = manager.get_total_items(); const double fraction_complete = - ((double) (current_bytes + current_items)) / (total_bytes + total_items); + ((double) (current_bytes + current_items)) / ((double) (total_bytes + total_items)); - const unsigned long time_remaining = + const unsigned long long time_remaining = download_rate == 0 ? 0 - : (total_bytes - current_bytes) / download_rate; + : ((unsigned long long) (total_bytes - current_bytes)) / download_rate; return boost::make_shared(manager.get_currentCPS(), active_downloads, diff --git a/src/generic/views/download_progress.h b/src/generic/views/download_progress.h index 1b6c919..3e41149 100644 --- a/src/generic/views/download_progress.h +++ b/src/generic/views/download_progress.h @@ -48,8 +48,8 @@ namespace aptitude /** \brief Represents the download progress of a single file. */ class file_progress { - unsigned long current_size; - unsigned long total_size; + unsigned long long current_size; + unsigned long long total_size; bool complete; std::string description; @@ -57,8 +57,8 @@ namespace aptitude std::string mode; public: - file_progress(unsigned long _current_size, - unsigned long _total_size, + file_progress(unsigned long long _current_size, + unsigned long long _total_size, bool _complete, const std::string &_description, const boost::optional &_id, @@ -74,10 +74,10 @@ namespace aptitude } /** \brief Get the number of bytes that have been downloaded. */ - unsigned long get_current_size() const { return current_size; } + unsigned long long get_current_size() const { return current_size; } /** \brief Get the total size of the file. */ - unsigned long get_total_size() const { return total_size; } + unsigned long long get_total_size() const { return total_size; } /** \return \b true if the file has been successfully fetched * according to the download backend. @@ -113,16 +113,16 @@ namespace aptitude typedef boost::variant worker_status; private: - const double download_rate; + const unsigned long long download_rate; const std::vector active_downloads; const double fraction_complete; - const unsigned long time_remaining; + const unsigned long long time_remaining; public: - status(const double _download_rate, + status(const unsigned long long _download_rate, const std::vector &_active_downloads, const double _fraction_complete, - const unsigned long _time_remaining) + const unsigned long long _time_remaining) : download_rate(_download_rate), active_downloads(_active_downloads), fraction_complete(_fraction_complete), @@ -131,7 +131,7 @@ namespace aptitude } /** \brief Get the current download speed in bytes per second. */ - double get_download_rate() const { return download_rate; } + unsigned long long get_download_rate() const { return download_rate; } /** \brief Get the currently active download processes. */ const std::vector &get_active_downloads() const @@ -147,7 +147,7 @@ namespace aptitude /** \brief Get the estimated number of seconds until the download * completes. */ - unsigned long get_time_remaining() const { return time_remaining; } + unsigned long long get_time_remaining() const { return time_remaining; } bool operator==(const status &other) const; bool operator!=(const status &other) const @@ -231,9 +231,9 @@ namespace aptitude * \todo Should the parameters be incorporated into a status * snapshot so that can be used instead? */ - virtual void done(double fetched_bytes, - unsigned long elapsed_time, - double latest_download_rate) = 0; + virtual void done(unsigned long long fetched_bytes, + unsigned long long elapsed_time, + unsigned long long latest_download_rate) = 0; /** \brief Invoked when the install media should be replaced. * @@ -258,9 +258,9 @@ namespace aptitude * * \param latest_download_rate The final estimated download rate. */ - virtual void complete(double fetched_bytes, - unsigned long elapsed_time, - double latest_download_rate) = 0; + virtual void complete(unsigned long long fetched_bytes, + unsigned long long elapsed_time, + unsigned long long latest_download_rate) = 0; }; std::ostream &operator<<(std::ostream &out, diff --git a/src/generic/views/mocks/download_progress.h b/src/generic/views/mocks/download_progress.h index 31fd928..3250abf 100644 --- a/src/generic/views/mocks/download_progress.h +++ b/src/generic/views/mocks/download_progress.h @@ -46,14 +46,14 @@ namespace aptitude MOCK_METHOD1(update_progress, bool(const status &)); MOCK_METHOD3(file_started, void(const std::string &, const boost::optional &, - const boost::optional &)); + const boost::optional &)); MOCK_METHOD4(error, void(bool, const std::string &, const std::string &, const boost::optional &)); MOCK_METHOD2(file_finished, void(const std::string &, const boost::optional &)); - MOCK_METHOD3(done, void(double, unsigned long, double)); + MOCK_METHOD3(done, void(unsigned long long, unsigned long long, unsigned long long)); MOCK_METHOD3(media_change, void(const std::string &, const std::string &, const sigc::slot1 &)); diff --git a/src/view_changelog.cc b/src/view_changelog.cc index caf5a32..8318a96 100644 --- a/src/view_changelog.cc +++ b/src/view_changelog.cc @@ -373,8 +373,8 @@ public: } void partial_download(const temp::name &name, - unsigned long currentSize, - unsigned long totalSize) + unsigned long long currentSize, + unsigned long long totalSize) { cwidget::util::ref_ptr p = download_progress->get_progress(); diff --git a/tests/test_cmdline_download_status_display.cc b/tests/test_cmdline_download_status_display.cc index 020e281..3938a38 100644 --- a/tests/test_cmdline_download_status_display.cc +++ b/tests/test_cmdline_download_status_display.cc @@ -278,18 +278,6 @@ TEST_P(CmdlineDownloadStatusDisplayTest, HasCpsNoFilesNoProgressNoTimeEstimate) 0)); } -// Test that updating the progress produces correct results when the -// download rate indicator is negative. -TEST_P(CmdlineDownloadStatusDisplayTest, HasNegativeCpsNoFilesNoProgressNoTimeEstimate) -{ - EXPECT_MSG(L"0% [Working]"); - - status_display->display_status(status(-20 * 1000, - make_files(), - 0, - 0)); -} - // Test that updating the progress produces correct results with a // time estimate. TEST_P(CmdlineDownloadStatusDisplayTest, NoCpsNoFilesNoProgressHasTimeEstimate) -- 1.7.9