]>
git.saurik.com Git - apt.git/blob - apt-pkg/acquire.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acquire.cc,v 1.50 2004/03/17 05:17:11 mdz Exp $
4 /* ######################################################################
6 Acquire - File Acquiration
8 The core element for the schedual system is the concept of a named
9 queue. Each queue is unique and each queue has a name derived from the
10 URI. The degree of paralization can be controled by how the queue
11 name is derived from the URI.
13 ##################################################################### */
15 // Include Files /*{{{*/
16 #include <apt-pkg/acquire.h>
17 #include <apt-pkg/acquire-item.h>
18 #include <apt-pkg/acquire-worker.h>
19 #include <apt-pkg/configuration.h>
20 #include <apt-pkg/error.h>
21 #include <apt-pkg/strutl.h>
22 #include <apt-pkg/fileutl.h>
37 // Acquire::pkgAcquire - Constructor /*{{{*/
38 // ---------------------------------------------------------------------
39 /* We grab some runtime state from the configuration space */
40 pkgAcquire::pkgAcquire() : Queues(0), Workers(0), Configs(0), Log(NULL
), ToFetch(0),
41 Debug(_config
->FindB("Debug::pkgAcquire",false)),
42 Running(false), LockFD(-1)
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
;
50 pkgAcquire::pkgAcquire(pkgAcquireStatus
*Progress
) : Queues(0), Workers(0),
51 Configs(0), Log(Progress
), ToFetch(0),
52 Debug(_config
->FindB("Debug::pkgAcquire",false)),
53 Running(false), LockFD(-1)
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
;
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
)
71 // check for existence and possibly create auxiliary directories
72 string
const listDir
= _config
->FindDir("Dir::State::lists");
73 string
const partialListDir
= listDir
+ "partial/";
74 string
const archivesDir
= _config
->FindDir("Dir::Cache::Archives");
75 string
const partialArchivesDir
= archivesDir
+ "partial/";
77 if (CreateAPTDirectoryIfNeeded(_config
->FindDir("Dir::State"), partialListDir
) == false &&
78 CreateAPTDirectoryIfNeeded(listDir
, partialListDir
) == false)
79 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());
85 if (Lock
.empty() == true || _config
->FindB("Debug::NoLocking", false) == true)
88 // Lock the directory this acquire object will work in
89 LockFD
= GetLock(flCombine(Lock
, "lock"));
91 return _error
->Error(_("Unable to lock directory %s"), Lock
.c_str());
96 // Acquire::~pkgAcquire - Destructor /*{{{*/
97 // ---------------------------------------------------------------------
98 /* Free our memory, clean up the queues (destroy the workers) */
99 pkgAcquire::~pkgAcquire()
108 MethodConfig
*Jnk
= Configs
;
109 Configs
= Configs
->Next
;
114 // Acquire::Shutdown - Clean out the acquire object /*{{{*/
115 // ---------------------------------------------------------------------
117 void pkgAcquire::Shutdown()
119 while (Items
.empty() == false)
121 if (Items
[0]->Status
== Item::StatFetching
)
122 Items
[0]->Status
= Item::StatError
;
129 Queues
= Queues
->Next
;
134 // Acquire::Add - Add a new item /*{{{*/
135 // ---------------------------------------------------------------------
136 /* This puts an item on the acquire list. This list is mainly for tracking
138 void pkgAcquire::Add(Item
*Itm
)
140 Items
.push_back(Itm
);
143 // Acquire::Remove - Remove a item /*{{{*/
144 // ---------------------------------------------------------------------
145 /* Remove an item from the acquire list. This is usually not used.. */
146 void pkgAcquire::Remove(Item
*Itm
)
150 for (ItemIterator I
= Items
.begin(); I
!= Items
.end();)
162 // Acquire::Add - Add a worker /*{{{*/
163 // ---------------------------------------------------------------------
164 /* A list of workers is kept so that the select loop can direct their FD
166 void pkgAcquire::Add(Worker
*Work
)
168 Work
->NextAcquire
= Workers
;
172 // Acquire::Remove - Remove a worker /*{{{*/
173 // ---------------------------------------------------------------------
174 /* A worker has died. This can not be done while the select loop is running
175 as it would require that RunFds could handling a changing list state and
177 void pkgAcquire::Remove(Worker
*Work
)
182 Worker
**I
= &Workers
;
186 *I
= (*I
)->NextAcquire
;
188 I
= &(*I
)->NextAcquire
;
192 // Acquire::Enqueue - Queue an URI for fetching /*{{{*/
193 // ---------------------------------------------------------------------
194 /* This is the entry point for an item. An item calls this function when
195 it is constructed which creates a queue (based on the current queue
196 mode) and puts the item in that queue. If the system is running then
197 the queue might be started. */
198 void pkgAcquire::Enqueue(ItemDesc
&Item
)
200 // Determine which queue to put the item in
201 const MethodConfig
*Config
;
202 string Name
= QueueName(Item
.URI
,Config
);
203 if (Name
.empty() == true)
206 // Find the queue structure
208 for (; I
!= 0 && I
->Name
!= Name
; I
= I
->Next
);
211 I
= new Queue(Name
,this);
219 // See if this is a local only URI
220 if (Config
->LocalOnly
== true && Item
.Owner
->Complete
== false)
221 Item
.Owner
->Local
= true;
222 Item
.Owner
->Status
= Item::StatIdle
;
224 // Queue it into the named queue
231 clog
<< "Fetching " << Item
.URI
<< endl
;
232 clog
<< " to " << Item
.Owner
->DestFile
<< endl
;
233 clog
<< " Queue is: " << Name
<< endl
;
237 // Acquire::Dequeue - Remove an item from all queues /*{{{*/
238 // ---------------------------------------------------------------------
239 /* This is called when an item is finished being fetched. It removes it
240 from all the queues */
241 void pkgAcquire::Dequeue(Item
*Itm
)
245 for (; I
!= 0; I
= I
->Next
)
246 Res
|= I
->Dequeue(Itm
);
249 clog
<< "Dequeuing " << Itm
->DestFile
<< endl
;
254 // Acquire::QueueName - Return the name of the queue for this URI /*{{{*/
255 // ---------------------------------------------------------------------
256 /* The string returned depends on the configuration settings and the
257 method parameters. Given something like http://foo.org/bar it can
258 return http://foo.org or http */
259 string
pkgAcquire::QueueName(string Uri
,MethodConfig
const *&Config
)
263 Config
= GetConfig(U
.Access
);
267 /* Single-Instance methods get exactly one queue per URI. This is
268 also used for the Access queue method */
269 if (Config
->SingleInstance
== true || QueueMode
== QueueAccess
)
272 return U
.Access
+ ':' + U
.Host
;
275 // Acquire::GetConfig - Fetch the configuration information /*{{{*/
276 // ---------------------------------------------------------------------
277 /* This locates the configuration structure for an access method. If
278 a config structure cannot be found a Worker will be created to
280 pkgAcquire::MethodConfig
*pkgAcquire::GetConfig(string Access
)
282 // Search for an existing config
284 for (Conf
= Configs
; Conf
!= 0; Conf
= Conf
->Next
)
285 if (Conf
->Access
== Access
)
288 // Create the new config class
289 Conf
= new MethodConfig
;
290 Conf
->Access
= Access
;
291 Conf
->Next
= Configs
;
294 // Create the worker to fetch the configuration
296 if (Work
.Start() == false)
299 /* if a method uses DownloadLimit, we switch to SingleInstance mode */
300 if(_config
->FindI("Acquire::"+Access
+"::Dl-Limit",0) > 0)
301 Conf
->SingleInstance
= true;
306 // Acquire::SetFds - Deal with readable FDs /*{{{*/
307 // ---------------------------------------------------------------------
308 /* Collect FDs that have activity monitors into the fd sets */
309 void pkgAcquire::SetFds(int &Fd
,fd_set
*RSet
,fd_set
*WSet
)
311 for (Worker
*I
= Workers
; I
!= 0; I
= I
->NextAcquire
)
313 if (I
->InReady
== true && I
->InFd
>= 0)
317 FD_SET(I
->InFd
,RSet
);
319 if (I
->OutReady
== true && I
->OutFd
>= 0)
323 FD_SET(I
->OutFd
,WSet
);
328 // Acquire::RunFds - Deal with active FDs /*{{{*/
329 // ---------------------------------------------------------------------
330 /* Dispatch active FDs over to the proper workers. It is very important
331 that a worker never be erased while this is running! The queue class
332 should never erase a worker except during shutdown processing. */
333 void pkgAcquire::RunFds(fd_set
*RSet
,fd_set
*WSet
)
335 for (Worker
*I
= Workers
; I
!= 0; I
= I
->NextAcquire
)
337 if (I
->InFd
>= 0 && FD_ISSET(I
->InFd
,RSet
) != 0)
339 if (I
->OutFd
>= 0 && FD_ISSET(I
->OutFd
,WSet
) != 0)
344 // Acquire::Run - Run the fetch sequence /*{{{*/
345 // ---------------------------------------------------------------------
346 /* This runs the queues. It manages a select loop for all of the
347 Worker tasks. The workers interact with the queues and items to
348 manage the actual fetch. */
349 pkgAcquire::RunResult
pkgAcquire::Run(int PulseIntervall
)
353 for (Queue
*I
= Queues
; I
!= 0; I
= I
->Next
)
359 bool WasCancelled
= false;
361 // Run till all things have been acquired
364 tv
.tv_usec
= PulseIntervall
;
372 SetFds(Highest
,&RFds
,&WFds
);
377 Res
= select(Highest
+1,&RFds
,&WFds
,0,&tv
);
379 while (Res
< 0 && errno
== EINTR
);
383 _error
->Errno("select","Select has failed");
388 if (_error
->PendingError() == true)
391 // Timeout, notify the log class
392 if (Res
== 0 || (Log
!= 0 && Log
->Update
== true))
394 tv
.tv_usec
= PulseIntervall
;
395 for (Worker
*I
= Workers
; I
!= 0; I
= I
->NextAcquire
)
397 if (Log
!= 0 && Log
->Pulse(this) == false)
408 // Shut down the acquire bits
410 for (Queue
*I
= Queues
; I
!= 0; I
= I
->Next
)
413 // Shut down the items
414 for (ItemIterator I
= Items
.begin(); I
!= Items
.end(); ++I
)
417 if (_error
->PendingError())
424 // Acquire::Bump - Called when an item is dequeued /*{{{*/
425 // ---------------------------------------------------------------------
426 /* This routine bumps idle queues in hopes that they will be able to fetch
428 void pkgAcquire::Bump()
430 for (Queue
*I
= Queues
; I
!= 0; I
= I
->Next
)
434 // Acquire::WorkerStep - Step to the next worker /*{{{*/
435 // ---------------------------------------------------------------------
436 /* Not inlined to advoid including acquire-worker.h */
437 pkgAcquire::Worker
*pkgAcquire::WorkerStep(Worker
*I
)
439 return I
->NextAcquire
;
442 // Acquire::Clean - Cleans a directory /*{{{*/
443 // ---------------------------------------------------------------------
444 /* This is a bit simplistic, it looks at every file in the dir and sees
445 if it is part of the download set. */
446 bool pkgAcquire::Clean(string Dir
)
448 // non-existing directories are by definition clean…
449 if (DirectoryExists(Dir
) == false)
452 DIR *D
= opendir(Dir
.c_str());
454 return _error
->Errno("opendir",_("Unable to read %s"),Dir
.c_str());
456 string StartDir
= SafeGetCWD();
457 if (chdir(Dir
.c_str()) != 0)
460 return _error
->Errno("chdir",_("Unable to change to %s"),Dir
.c_str());
463 for (struct dirent
*Dir
= readdir(D
); Dir
!= 0; Dir
= readdir(D
))
466 if (strcmp(Dir
->d_name
,"lock") == 0 ||
467 strcmp(Dir
->d_name
,"partial") == 0 ||
468 strcmp(Dir
->d_name
,".") == 0 ||
469 strcmp(Dir
->d_name
,"..") == 0)
472 // Look in the get list
473 ItemCIterator I
= Items
.begin();
474 for (; I
!= Items
.end(); ++I
)
475 if (flNotDir((*I
)->DestFile
) == Dir
->d_name
)
478 // Nothing found, nuke it
479 if (I
== Items
.end())
484 if (chdir(StartDir
.c_str()) != 0)
485 return _error
->Errno("chdir",_("Unable to change to %s"),StartDir
.c_str());
489 // Acquire::TotalNeeded - Number of bytes to fetch /*{{{*/
490 // ---------------------------------------------------------------------
491 /* This is the total number of bytes needed */
492 unsigned long long pkgAcquire::TotalNeeded()
494 unsigned long long Total
= 0;
495 for (ItemCIterator I
= ItemsBegin(); I
!= ItemsEnd(); ++I
)
496 Total
+= (*I
)->FileSize
;
500 // Acquire::FetchNeeded - Number of bytes needed to get /*{{{*/
501 // ---------------------------------------------------------------------
502 /* This is the number of bytes that is not local */
503 unsigned long long pkgAcquire::FetchNeeded()
505 unsigned long long Total
= 0;
506 for (ItemCIterator I
= ItemsBegin(); I
!= ItemsEnd(); ++I
)
507 if ((*I
)->Local
== false)
508 Total
+= (*I
)->FileSize
;
512 // Acquire::PartialPresent - Number of partial bytes we already have /*{{{*/
513 // ---------------------------------------------------------------------
514 /* This is the number of bytes that is not local */
515 unsigned long long pkgAcquire::PartialPresent()
517 unsigned long long Total
= 0;
518 for (ItemCIterator I
= ItemsBegin(); I
!= ItemsEnd(); ++I
)
519 if ((*I
)->Local
== false)
520 Total
+= (*I
)->PartialSize
;
524 // Acquire::UriBegin - Start iterator for the uri list /*{{{*/
525 // ---------------------------------------------------------------------
527 pkgAcquire::UriIterator
pkgAcquire::UriBegin()
529 return UriIterator(Queues
);
532 // Acquire::UriEnd - End iterator for the uri list /*{{{*/
533 // ---------------------------------------------------------------------
535 pkgAcquire::UriIterator
pkgAcquire::UriEnd()
537 return UriIterator(0);
540 // Acquire::MethodConfig::MethodConfig - Constructor /*{{{*/
541 // ---------------------------------------------------------------------
543 pkgAcquire::MethodConfig::MethodConfig()
545 SingleInstance
= false;
553 // Queue::Queue - Constructor /*{{{*/
554 // ---------------------------------------------------------------------
556 pkgAcquire::Queue::Queue(string Name
,pkgAcquire
*Owner
) : Name(Name
),
566 // Queue::~Queue - Destructor /*{{{*/
567 // ---------------------------------------------------------------------
569 pkgAcquire::Queue::~Queue()
581 // Queue::Enqueue - Queue an item to the queue /*{{{*/
582 // ---------------------------------------------------------------------
584 bool pkgAcquire::Queue::Enqueue(ItemDesc
&Item
)
587 // move to the end of the queue and check for duplicates here
588 for (; *I
!= 0; I
= &(*I
)->Next
)
589 if (Item
.URI
== (*I
)->URI
)
591 Item
.Owner
->Status
= Item::StatDone
;
596 QItem
*Itm
= new QItem
;
601 Item
.Owner
->QueueCounter
++;
602 if (Items
->Next
== 0)
607 // Queue::Dequeue - Remove an item from the queue /*{{{*/
608 // ---------------------------------------------------------------------
609 /* We return true if we hit something */
610 bool pkgAcquire::Queue::Dequeue(Item
*Owner
)
612 if (Owner
->Status
== pkgAcquire::Item::StatFetching
)
613 return _error
->Error("Tried to dequeue a fetching object");
620 if ((*I
)->Owner
== Owner
)
624 Owner
->QueueCounter
--;
635 // Queue::Startup - Start the worker processes /*{{{*/
636 // ---------------------------------------------------------------------
637 /* It is possible for this to be called with a pre-existing set of
639 bool pkgAcquire::Queue::Startup()
644 pkgAcquire::MethodConfig
*Cnf
= Owner
->GetConfig(U
.Access
);
648 Workers
= new Worker(this,Cnf
,Owner
->Log
);
650 if (Workers
->Start() == false)
653 /* When pipelining we commit 10 items. This needs to change when we
654 added other source retry to have cycle maintain a pipeline depth
656 if (Cnf
->Pipeline
== true)
657 MaxPipeDepth
= _config
->FindI("Acquire::Max-Pipeline-Depth",10);
665 // Queue::Shutdown - Shutdown the worker processes /*{{{*/
666 // ---------------------------------------------------------------------
667 /* If final is true then all workers are eliminated, otherwise only workers
668 that do not need cleanup are removed */
669 bool pkgAcquire::Queue::Shutdown(bool Final
)
671 // Delete all of the workers
672 pkgAcquire::Worker
**Cur
= &Workers
;
675 pkgAcquire::Worker
*Jnk
= *Cur
;
676 if (Final
== true || Jnk
->GetConf()->NeedsCleanup
== false)
678 *Cur
= Jnk
->NextQueue
;
683 Cur
= &(*Cur
)->NextQueue
;
689 // Queue::FindItem - Find a URI in the item list /*{{{*/
690 // ---------------------------------------------------------------------
692 pkgAcquire::Queue::QItem
*pkgAcquire::Queue::FindItem(string URI
,pkgAcquire::Worker
*Owner
)
694 for (QItem
*I
= Items
; I
!= 0; I
= I
->Next
)
695 if (I
->URI
== URI
&& I
->Worker
== Owner
)
700 // Queue::ItemDone - Item has been completed /*{{{*/
701 // ---------------------------------------------------------------------
702 /* The worker signals this which causes the item to be removed from the
703 queue. If this is the last queue instance then it is removed from the
705 bool pkgAcquire::Queue::ItemDone(QItem
*Itm
)
708 if (Itm
->Owner
->Status
== pkgAcquire::Item::StatFetching
)
709 Itm
->Owner
->Status
= pkgAcquire::Item::StatDone
;
711 if (Itm
->Owner
->QueueCounter
<= 1)
712 Owner
->Dequeue(Itm
->Owner
);
722 // Queue::Cycle - Queue new items into the method /*{{{*/
723 // ---------------------------------------------------------------------
724 /* This locates a new idle item and sends it to the worker. If pipelining
725 is enabled then it keeps the pipe full. */
726 bool pkgAcquire::Queue::Cycle()
728 if (Items
== 0 || Workers
== 0)
732 return _error
->Error("Pipedepth failure");
734 // Look for a queable item
736 while (PipeDepth
< (signed)MaxPipeDepth
)
738 for (; I
!= 0; I
= I
->Next
)
739 if (I
->Owner
->Status
== pkgAcquire::Item::StatIdle
)
742 // Nothing to do, queue is idle.
747 I
->Owner
->Status
= pkgAcquire::Item::StatFetching
;
749 if (Workers
->QueueItem(I
) == false)
756 // Queue::Bump - Fetch any pending objects if we are idle /*{{{*/
757 // ---------------------------------------------------------------------
758 /* This is called when an item in multiple queues is dequeued */
759 void pkgAcquire::Queue::Bump()
764 // AcquireStatus::pkgAcquireStatus - Constructor /*{{{*/
765 // ---------------------------------------------------------------------
767 pkgAcquireStatus::pkgAcquireStatus() : Update(true), MorePulses(false)
772 // AcquireStatus::Pulse - Called periodically /*{{{*/
773 // ---------------------------------------------------------------------
774 /* This computes some internal state variables for the derived classes to
775 use. It generates the current downloaded bytes and total bytes to download
776 as well as the current CPS estimate. */
777 bool pkgAcquireStatus::Pulse(pkgAcquire
*Owner
)
784 // Compute the total number of bytes to fetch
785 unsigned int Unknown
= 0;
786 unsigned int Count
= 0;
787 for (pkgAcquire::ItemCIterator I
= Owner
->ItemsBegin(); I
!= Owner
->ItemsEnd();
791 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
794 // Totally ignore local items
795 if ((*I
)->Local
== true)
798 TotalBytes
+= (*I
)->FileSize
;
799 if ((*I
)->Complete
== true)
800 CurrentBytes
+= (*I
)->FileSize
;
801 if ((*I
)->FileSize
== 0 && (*I
)->Complete
== false)
805 // Compute the current completion
806 unsigned long ResumeSize
= 0;
807 for (pkgAcquire::Worker
*I
= Owner
->WorkersBegin(); I
!= 0;
808 I
= Owner
->WorkerStep(I
))
809 if (I
->CurrentItem
!= 0 && I
->CurrentItem
->Owner
->Complete
== false)
811 CurrentBytes
+= I
->CurrentSize
;
812 ResumeSize
+= I
->ResumePoint
;
814 // Files with unknown size always have 100% completion
815 if (I
->CurrentItem
->Owner
->FileSize
== 0 &&
816 I
->CurrentItem
->Owner
->Complete
== false)
817 TotalBytes
+= I
->CurrentSize
;
820 // Normalize the figures and account for unknown size downloads
823 if (Unknown
== Count
)
824 TotalBytes
= Unknown
;
826 // Wha?! Is not supposed to happen.
827 if (CurrentBytes
> TotalBytes
)
828 CurrentBytes
= TotalBytes
;
831 struct timeval NewTime
;
832 gettimeofday(&NewTime
,0);
833 if ((NewTime
.tv_sec
- Time
.tv_sec
== 6 && NewTime
.tv_usec
> Time
.tv_usec
) ||
834 NewTime
.tv_sec
- Time
.tv_sec
> 6)
836 double Delta
= NewTime
.tv_sec
- Time
.tv_sec
+
837 (NewTime
.tv_usec
- Time
.tv_usec
)/1000000.0;
839 // Compute the CPS value
843 CurrentCPS
= ((CurrentBytes
- ResumeSize
) - LastBytes
)/Delta
;
844 LastBytes
= CurrentBytes
- ResumeSize
;
845 ElapsedTime
= (unsigned long)Delta
;
849 int fd
= _config
->FindI("APT::Status-Fd",-1);
852 ostringstream status
;
855 long i
= CurrentItems
< TotalItems
? CurrentItems
+ 1 : CurrentItems
;
857 (unsigned long)((TotalBytes
- CurrentBytes
) / CurrentCPS
);
859 // only show the ETA if it makes sense
860 if (ETA
> 0 && ETA
< 172800 /* two days */ )
861 snprintf(msg
,sizeof(msg
), _("Retrieving file %li of %li (%s remaining)"), i
, TotalItems
, TimeToStr(ETA
).c_str());
863 snprintf(msg
,sizeof(msg
), _("Retrieving file %li of %li"), i
, TotalItems
);
867 // build the status str
868 status
<< "dlstatus:" << i
869 << ":" << (CurrentBytes
/float(TotalBytes
)*100.0)
872 write(fd
, status
.str().c_str(), status
.str().size());
878 // AcquireStatus::Start - Called when the download is started /*{{{*/
879 // ---------------------------------------------------------------------
880 /* We just reset the counters */
881 void pkgAcquireStatus::Start()
883 gettimeofday(&Time
,0);
884 gettimeofday(&StartTime
,0);
895 // AcquireStatus::Stop - Finished downloading /*{{{*/
896 // ---------------------------------------------------------------------
897 /* This accurately computes the elapsed time and the total overall CPS. */
898 void pkgAcquireStatus::Stop()
900 // Compute the CPS and elapsed time
901 struct timeval NewTime
;
902 gettimeofday(&NewTime
,0);
904 double Delta
= NewTime
.tv_sec
- StartTime
.tv_sec
+
905 (NewTime
.tv_usec
- StartTime
.tv_usec
)/1000000.0;
907 // Compute the CPS value
911 CurrentCPS
= FetchedBytes
/Delta
;
912 LastBytes
= CurrentBytes
;
913 ElapsedTime
= (unsigned int)Delta
;
916 // AcquireStatus::Fetched - Called when a byte set has been fetched /*{{{*/
917 // ---------------------------------------------------------------------
918 /* This is used to get accurate final transfer rate reporting. */
919 void pkgAcquireStatus::Fetched(unsigned long Size
,unsigned long Resume
)
921 FetchedBytes
+= Size
- Resume
;