diff options
author | Arch Librarian <arch@canonical.com> | 2004-09-20 16:51:12 +0000 |
---|---|---|
committer | Arch Librarian <arch@canonical.com> | 2004-09-20 16:51:12 +0000 |
commit | 8b89e57fa2ae7d34b055b8f804cee0c2c194043b (patch) | |
tree | e064dc401cfa03ed15eaafbc746ecd9bb379a211 /apt-pkg/acquire-item.cc | |
parent | 92173b19af439ac49d842902a3a57105d396d7d8 (diff) |
Stable acquire code
Author: jgg
Date: 1998-10-26 07:11:43 GMT
Stable acquire code
Diffstat (limited to 'apt-pkg/acquire-item.cc')
-rw-r--r-- | apt-pkg/acquire-item.cc | 86 |
1 files changed, 76 insertions, 10 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index e6eee197b..4435e2553 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: acquire-item.cc,v 1.4 1998/10/24 04:57:56 jgg Exp $ +// $Id: acquire-item.cc,v 1.5 1998/10/26 07:11:43 jgg Exp $ /* ###################################################################### Acquire Item - Item to acquire @@ -65,6 +65,22 @@ void pkgAcquire::Item::Done(string,unsigned long,string) Owner->Dequeue(this); } /*}}}*/ +// Acquire::Item::Rename - Rename a file /*{{{*/ +// --------------------------------------------------------------------- +/* This helper function is used by alot of item methods as thier final + step */ +void pkgAcquire::Item::Rename(string From,string To) +{ + if (rename(From.c_str(),To.c_str()) != 0) + { + char S[300]; + sprintf(S,"rename failed, %s (%s -> %s).",strerror(errno), + From.c_str(),To.c_str()); + Status = StatError; + ErrorText = S; + } +} + /*}}}*/ // AcqIndex::AcqIndex - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -73,6 +89,8 @@ void pkgAcquire::Item::Done(string,unsigned long,string) pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location) : Item(Owner), Location(Location) { + Decompression = false; + DestFile = _config->FindDir("Dir::State::lists") + "partial/"; DestFile += URItoFileName(Location->PackagesURI()); @@ -97,6 +115,57 @@ string pkgAcqIndex::Custom600Headers() return "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime); } /*}}}*/ +// AcqIndex::Done - Finished a fetch /*{{{*/ +// --------------------------------------------------------------------- +/* This goes through a number of states.. On the initial fetch the + method could possibly return an alternate filename which points + to the uncompressed version of the file. If this is so the file + is copied into the partial directory. In all other cases the file + is decompressed with a gzip uri. */ +void pkgAcqIndex::Done(string Message,unsigned long Size,string MD5) +{ + Item::Done(Message,Size,MD5); + + if (Decompression == true) + { + // Done, move it into position + string FinalFile = _config->FindDir("Dir::State::lists"); + FinalFile += URItoFileName(Location->PackagesURI()); + Rename(DestFile,FinalFile); + return; + } + + // Handle the unzipd case + string FileName = LookupTag(Message,"Alt-Filename"); + if (FileName.empty() == false) + { + // The files timestamp matches + if (StringToBool(LookupTag(Message,"Alt-IMS-Hit"),false) == true) + return; + + Decompression = true; + DestFile += ".decomp"; + QueueURI("copy:" + FileName,string()); + return; + } + + FileName = LookupTag(Message,"Filename"); + if (FileName.empty() == true) + { + Status = StatError; + ErrorText = "Method gave a blank filename"; + } + + // The files timestamp matches + if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true) + return; + + Decompression = true; + DestFile += ".decomp"; + QueueURI("gzip:" + FileName,string()); +} + /*}}}*/ + // AcqIndexRel::pkgAcqIndexRel - Constructor /*{{{*/ // --------------------------------------------------------------------- /* The Release file is added to the queue */ @@ -139,7 +208,12 @@ void pkgAcqIndexRel::Done(string Message,unsigned long Size,string MD5) { Status = StatError; ErrorText = "Method gave a blank filename"; + return; } + + // The files timestamp matches + if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true) + return; // We have to copy it into place if (FileName != DestFile) @@ -151,14 +225,6 @@ void pkgAcqIndexRel::Done(string Message,unsigned long Size,string MD5) // Done, move it into position string FinalFile = _config->FindDir("Dir::State::lists"); FinalFile += URItoFileName(Location->ReleaseURI()); - - if (rename(DestFile.c_str(),FinalFile.c_str()) != 0) - { - char S[300]; - sprintf(S,"rename failed, %s (%s -> %s).",strerror(errno), - DestFile.c_str(),FinalFile.c_str()); - Status = StatError; - ErrorText = S; - } + Rename(DestFile,FinalFile); } /*}}}*/ |