Retries and tweaked dselect script
[ntk/apt.git] / apt-pkg / acquire-item.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: acquire-item.h,v 1.22 1999/10/17 20:58:36 jgg Exp $
4 /* ######################################################################
5
6 Acquire Item - Item to acquire
7
8 When an item is instantiated it will add it self to the local list in
9 the Owner Acquire class. Derived classes will then call QueueURI to
10 register all the URI's they wish to fetch at the initial moment.
11
12 Two item classes are provided to provide functionality for downloading
13 of Index files and downloading of Packages.
14
15 A Archive class is provided for downloading .deb files. It does Md5
16 checking and source location as well as a retry algorithm.
17
18 ##################################################################### */
19 /*}}}*/
20 #ifndef PKGLIB_ACQUIRE_ITEM_H
21 #define PKGLIB_ACQUIRE_ITEM_H
22
23 #include <apt-pkg/acquire.h>
24 #include <apt-pkg/sourcelist.h>
25 #include <apt-pkg/pkgrecords.h>
26
27 #ifdef __GNUG__
28 #pragma interface "apt-pkg/acquire-item.h"
29 #endif
30
31 // Item to acquire
32 class pkgAcquire::Item
33 {
34 protected:
35
36 // Some private helper methods for registering URIs
37 pkgAcquire *Owner;
38 inline void QueueURI(ItemDesc &Item)
39 {Owner->Enqueue(Item);};
40 inline void Dequeue() {Owner->Dequeue(this);};
41
42 // Safe rename function with timestamp preservation
43 void Rename(string From,string To);
44
45 public:
46
47 // State of the item
48 enum {StatIdle, StatFetching, StatDone, StatError} Status;
49 string ErrorText;
50 unsigned long FileSize;
51 unsigned long PartialSize;
52 char *Mode;
53 unsigned long ID;
54 bool Complete;
55 bool Local;
56
57 // Number of queues we are inserted into
58 unsigned int QueueCounter;
59
60 // File to write the fetch into
61 string DestFile;
62
63 // Action members invoked by the worker
64 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
65 virtual void Done(string Message,unsigned long Size,string Md5Hash);
66 virtual void Start(string Message,unsigned long Size);
67 virtual string Custom600Headers() {return string();};
68 virtual string DescURI() = 0;
69 virtual void Finished() {};
70
71 // Inquire functions
72 virtual string MD5Sum() {return string();};
73
74 Item(pkgAcquire *Owner);
75 virtual ~Item();
76 };
77
78 // Item class for index files
79 class pkgAcqIndex : public pkgAcquire::Item
80 {
81 protected:
82
83 const pkgSourceList::Item *Location;
84 bool Decompression;
85 bool Erase;
86 pkgAcquire::ItemDesc Desc;
87
88 public:
89
90 // Specialized action members
91 virtual void Done(string Message,unsigned long Size,string Md5Hash);
92 virtual string Custom600Headers();
93 virtual string DescURI() {return Location->PackagesURI();};
94
95 pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location);
96 };
97
98 // Item class for index files
99 class pkgAcqIndexRel : public pkgAcquire::Item
100 {
101 protected:
102
103 const pkgSourceList::Item *Location;
104 pkgAcquire::ItemDesc Desc;
105
106 public:
107
108 // Specialized action members
109 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
110 virtual void Done(string Message,unsigned long Size,string Md5Hash);
111 virtual string Custom600Headers();
112 virtual string DescURI() {return Location->ReleaseURI();};
113
114 pkgAcqIndexRel(pkgAcquire *Owner,const pkgSourceList::Item *Location);
115 };
116
117 // Item class for archive files
118 class pkgAcqArchive : public pkgAcquire::Item
119 {
120 protected:
121
122 // State information for the retry mechanism
123 pkgCache::VerIterator Version;
124 pkgAcquire::ItemDesc Desc;
125 pkgSourceList *Sources;
126 pkgRecords *Recs;
127 string MD5;
128 string &StoreFilename;
129 pkgCache::VerFileIterator Vf;
130 unsigned int Retries;
131
132 // Queue the next available file for download.
133 bool QueueNext();
134
135 public:
136
137 // Specialized action members
138 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
139 virtual void Done(string Message,unsigned long Size,string Md5Hash);
140 virtual string MD5Sum() {return MD5;};
141 virtual string DescURI() {return Desc.URI;};
142 virtual void Finished();
143
144 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
145 pkgRecords *Recs,pkgCache::VerIterator const &Version,
146 string &StoreFilename);
147 };
148
149 // Fetch a generic file to the current directory
150 class pkgAcqFile : public pkgAcquire::Item
151 {
152 pkgAcquire::ItemDesc Desc;
153 string Md5Hash;
154 unsigned int Retries;
155
156 public:
157
158 // Specialized action members
159 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
160 virtual void Done(string Message,unsigned long Size,string Md5Hash);
161 virtual string MD5Sum() {return Md5Hash;};
162 virtual string DescURI() {return Desc.URI;};
163
164 pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,unsigned long Size,
165 string Desc,string ShortDesc);
166 };
167
168 #endif