]> git.saurik.com Git - apt.git/blame - apt-pkg/acquire-item.cc
gzip method
[apt.git] / apt-pkg / acquire-item.cc
CommitLineData
0118833a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
c88edf1d 3// $Id: acquire-item.cc,v 1.4 1998/10/24 04:57:56 jgg Exp $
0118833a
AL
4/* ######################################################################
5
6 Acquire Item - Item to acquire
7
8 Each item can download to exactly one file at a time. This means you
9 cannot create an item that fetches two uri's to two files at the same
10 time. The pkgAcqIndex class creates a second class upon instantiation
11 to fetch the other index files because of this.
12
13 ##################################################################### */
14 /*}}}*/
15// Include Files /*{{{*/
16#ifdef __GNUG__
17#pragma implementation "apt-pkg/acquire-item.h"
18#endif
19#include <apt-pkg/acquire-item.h>
20#include <apt-pkg/configuration.h>
21#include <strutl.h>
0a8a80e5
AL
22
23#include <sys/stat.h>
24#include <unistd.h>
c88edf1d
AL
25#include <errno.h>
26#include <string.h>
27#include <stdio.h>
0118833a
AL
28 /*}}}*/
29
30// Acquire::Item::Item - Constructor /*{{{*/
31// ---------------------------------------------------------------------
32/* */
33pkgAcquire::Item::Item(pkgAcquire *Owner) : Owner(Owner), QueueCounter(0)
34{
35 Owner->Add(this);
c88edf1d 36 Status = StatIdle;
0118833a
AL
37}
38 /*}}}*/
39// Acquire::Item::~Item - Destructor /*{{{*/
40// ---------------------------------------------------------------------
41/* */
42pkgAcquire::Item::~Item()
43{
44 Owner->Remove(this);
45}
46 /*}}}*/
c88edf1d
AL
47// Acquire::Item::Failed - Item failed to download /*{{{*/
48// ---------------------------------------------------------------------
49/* */
50void pkgAcquire::Item::Failed(string Message)
51{
52 Status = StatError;
53 ErrorText = LookupTag(Message,"Message");
54 if (QueueCounter <= 1)
55 Owner->Dequeue(this);
56}
57 /*}}}*/
58// Acquire::Item::Done - Item downloaded OK /*{{{*/
59// ---------------------------------------------------------------------
60/* */
61void pkgAcquire::Item::Done(string,unsigned long,string)
62{
63 Status = StatDone;
64 ErrorText = string();
65 Owner->Dequeue(this);
66}
67 /*}}}*/
0118833a
AL
68
69// AcqIndex::AcqIndex - Constructor /*{{{*/
70// ---------------------------------------------------------------------
71/* The package file is added to the queue and a second class is
72 instantiated to fetch the revision file */
73pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location) :
74 Item(Owner), Location(Location)
75{
0a8a80e5
AL
76 DestFile = _config->FindDir("Dir::State::lists") + "partial/";
77 DestFile += URItoFileName(Location->PackagesURI());
78
79 QueueURI(Location->PackagesURI() + ".gz",Location->PackagesInfo());
0118833a 80
0a8a80e5 81 // Create the Release fetch class
0118833a
AL
82 new pkgAcqIndexRel(Owner,Location);
83}
84 /*}}}*/
0a8a80e5 85// AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
0118833a 86// ---------------------------------------------------------------------
0a8a80e5
AL
87/* The only header we use is the last-modified header. */
88string pkgAcqIndex::Custom600Headers()
0118833a 89{
0a8a80e5
AL
90 string Final = _config->FindDir("Dir::State::lists");
91 Final += URItoFileName(Location->PackagesURI());
92
93 struct stat Buf;
94 if (stat(Final.c_str(),&Buf) != 0)
95 return string();
0118833a 96
0a8a80e5 97 return "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
0118833a
AL
98}
99 /*}}}*/
0118833a
AL
100// AcqIndexRel::pkgAcqIndexRel - Constructor /*{{{*/
101// ---------------------------------------------------------------------
102/* The Release file is added to the queue */
103pkgAcqIndexRel::pkgAcqIndexRel(pkgAcquire *Owner,
104 const pkgSourceList::Item *Location) :
105 Item(Owner), Location(Location)
106{
0a8a80e5
AL
107 DestFile = _config->FindDir("Dir::State::lists") + "partial/";
108 DestFile += URItoFileName(Location->ReleaseURI());
109
110 QueueURI(Location->ReleaseURI(),Location->ReleaseInfo());
0118833a
AL
111}
112 /*}}}*/
0a8a80e5 113// AcqIndexRel::Custom600Headers - Insert custom request headers /*{{{*/
0118833a 114// ---------------------------------------------------------------------
0a8a80e5
AL
115/* The only header we use is the last-modified header. */
116string pkgAcqIndexRel::Custom600Headers()
0118833a 117{
0a8a80e5
AL
118 string Final = _config->FindDir("Dir::State::lists");
119 Final += URItoFileName(Location->ReleaseURI());
120
121 struct stat Buf;
122 if (stat(Final.c_str(),&Buf) != 0)
123 return string();
0118833a 124
0a8a80e5 125 return "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
0118833a
AL
126}
127 /*}}}*/
c88edf1d
AL
128// AcqIndexRel::Done - Item downloaded OK /*{{{*/
129// ---------------------------------------------------------------------
130/* The release file was not placed into the download directory then
131 a copy URI is generated and it is copied there otherwise the file
132 in the partial directory is moved into .. and the URI is finished. */
133void pkgAcqIndexRel::Done(string Message,unsigned long Size,string MD5)
134{
135 Item::Done(Message,Size,MD5);
136
137 string FileName = LookupTag(Message,"Filename");
138 if (FileName.empty() == true)
139 {
140 Status = StatError;
141 ErrorText = "Method gave a blank filename";
142 }
143
144 // We have to copy it into place
145 if (FileName != DestFile)
146 {
147 QueueURI("copy:" + FileName,string());
148 return;
149 }
150
151 // Done, move it into position
152 string FinalFile = _config->FindDir("Dir::State::lists");
153 FinalFile += URItoFileName(Location->ReleaseURI());
154
155 if (rename(DestFile.c_str(),FinalFile.c_str()) != 0)
156 {
157 char S[300];
158 sprintf(S,"rename failed, %s (%s -> %s).",strerror(errno),
159 DestFile.c_str(),FinalFile.c_str());
160 Status = StatError;
161 ErrorText = S;
162 }
163}
164 /*}}}*/