Sync
[ntk/apt.git] / apt-pkg / acquire-item.cc
CommitLineData
0118833a
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
0a8a80e5 3// $Id: acquire-item.cc,v 1.3 1998/10/22 04:56:38 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>
0118833a
AL
25 /*}}}*/
26
27// Acquire::Item::Item - Constructor /*{{{*/
28// ---------------------------------------------------------------------
29/* */
30pkgAcquire::Item::Item(pkgAcquire *Owner) : Owner(Owner), QueueCounter(0)
31{
32 Owner->Add(this);
33}
34 /*}}}*/
35// Acquire::Item::~Item - Destructor /*{{{*/
36// ---------------------------------------------------------------------
37/* */
38pkgAcquire::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 */
48pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location) :
49 Item(Owner), Location(Location)
50{
0a8a80e5
AL
51 DestFile = _config->FindDir("Dir::State::lists") + "partial/";
52 DestFile += URItoFileName(Location->PackagesURI());
53
54 QueueURI(Location->PackagesURI() + ".gz",Location->PackagesInfo());
0118833a 55
0a8a80e5 56 // Create the Release fetch class
0118833a
AL
57 new pkgAcqIndexRel(Owner,Location);
58}
59 /*}}}*/
0a8a80e5 60// AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
0118833a 61// ---------------------------------------------------------------------
0a8a80e5
AL
62/* The only header we use is the last-modified header. */
63string pkgAcqIndex::Custom600Headers()
0118833a 64{
0a8a80e5
AL
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();
0118833a 71
0a8a80e5 72 return "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
0118833a
AL
73}
74 /*}}}*/
0118833a
AL
75// AcqIndexRel::pkgAcqIndexRel - Constructor /*{{{*/
76// ---------------------------------------------------------------------
77/* The Release file is added to the queue */
78pkgAcqIndexRel::pkgAcqIndexRel(pkgAcquire *Owner,
79 const pkgSourceList::Item *Location) :
80 Item(Owner), Location(Location)
81{
0a8a80e5
AL
82 DestFile = _config->FindDir("Dir::State::lists") + "partial/";
83 DestFile += URItoFileName(Location->ReleaseURI());
84
85 QueueURI(Location->ReleaseURI(),Location->ReleaseInfo());
0118833a
AL
86}
87 /*}}}*/
0a8a80e5 88// AcqIndexRel::Custom600Headers - Insert custom request headers /*{{{*/
0118833a 89// ---------------------------------------------------------------------
0a8a80e5
AL
90/* The only header we use is the last-modified header. */
91string pkgAcqIndexRel::Custom600Headers()
0118833a 92{
0a8a80e5
AL
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();
0118833a 99
0a8a80e5 100 return "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
0118833a
AL
101}
102 /*}}}*/