]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.cc
Sync
[apt.git] / apt-pkg / acquire-item.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: acquire-item.cc,v 1.3 1998/10/22 04:56:38 jgg Exp $
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>
22
23 #include <sys/stat.h>
24 #include <unistd.h>
25 /*}}}*/
26
27 // Acquire::Item::Item - Constructor /*{{{*/
28 // ---------------------------------------------------------------------
29 /* */
30 pkgAcquire::Item::Item(pkgAcquire *Owner) : Owner(Owner), QueueCounter(0)
31 {
32 Owner->Add(this);
33 }
34 /*}}}*/
35 // Acquire::Item::~Item - Destructor /*{{{*/
36 // ---------------------------------------------------------------------
37 /* */
38 pkgAcquire::Item::~Item()
39 {
40 Owner->Remove(this);
41 }
42 /*}}}*/
43
44 // AcqIndex::AcqIndex - Constructor /*{{{*/
45 // ---------------------------------------------------------------------
46 /* The package file is added to the queue and a second class is
47 instantiated to fetch the revision file */
48 pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location) :
49 Item(Owner), Location(Location)
50 {
51 DestFile = _config->FindDir("Dir::State::lists") + "partial/";
52 DestFile += URItoFileName(Location->PackagesURI());
53
54 QueueURI(Location->PackagesURI() + ".gz",Location->PackagesInfo());
55
56 // Create the Release fetch class
57 new pkgAcqIndexRel(Owner,Location);
58 }
59 /*}}}*/
60 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
61 // ---------------------------------------------------------------------
62 /* The only header we use is the last-modified header. */
63 string pkgAcqIndex::Custom600Headers()
64 {
65 string Final = _config->FindDir("Dir::State::lists");
66 Final += URItoFileName(Location->PackagesURI());
67
68 struct stat Buf;
69 if (stat(Final.c_str(),&Buf) != 0)
70 return string();
71
72 return "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
73 }
74 /*}}}*/
75 // AcqIndexRel::pkgAcqIndexRel - Constructor /*{{{*/
76 // ---------------------------------------------------------------------
77 /* The Release file is added to the queue */
78 pkgAcqIndexRel::pkgAcqIndexRel(pkgAcquire *Owner,
79 const pkgSourceList::Item *Location) :
80 Item(Owner), Location(Location)
81 {
82 DestFile = _config->FindDir("Dir::State::lists") + "partial/";
83 DestFile += URItoFileName(Location->ReleaseURI());
84
85 QueueURI(Location->ReleaseURI(),Location->ReleaseInfo());
86 }
87 /*}}}*/
88 // AcqIndexRel::Custom600Headers - Insert custom request headers /*{{{*/
89 // ---------------------------------------------------------------------
90 /* The only header we use is the last-modified header. */
91 string pkgAcqIndexRel::Custom600Headers()
92 {
93 string Final = _config->FindDir("Dir::State::lists");
94 Final += URItoFileName(Location->ReleaseURI());
95
96 struct stat Buf;
97 if (stat(Final.c_str(),&Buf) != 0)
98 return string();
99
100 return "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
101 }
102 /*}}}*/