summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2014-07-22 11:35:30 +0200
committerMichael Vogt <mvo@ubuntu.com>2014-07-22 11:44:29 +0200
commit1f4dd8fd8489fbfd62c4d1667f159433a5f532b2 (patch)
tree4b7a8b70ba0bd07708d4718f8f05f0cae866e300 /apt-pkg
parent2737f28a1cb2d03c66d2a7edd04215566903dbf1 (diff)
WIP cleanup pkgAcqMetaSig
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/acquire-item.cc119
-rw-r--r--apt-pkg/acquire-item.h5
-rw-r--r--apt-pkg/acquire.cc1
3 files changed, 42 insertions, 83 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index fa41bca7a..01e1841d6 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -135,7 +135,7 @@ void pkgAcquire::Item::Done(string Message,unsigned long long Size,HashStringLis
{
// We just downloaded something..
string FileName = LookupTag(Message,"Filename");
- UsedMirror = LookupTag(Message,"UsedMirror");
+ UsedMirror = LookupTag(Message,"UsedMirror");
if (Complete == false && !Local && FileName == DestFile)
{
if (Owner->Log != 0)
@@ -1322,55 +1322,30 @@ pkgAcqMetaSig::pkgAcqMetaSig(pkgAcqMetaIndex *MetaOwner, /*{{{*/
indexRecords* MetaIndexParser) :
Item(MetaOwner->GetOwner(), HashStringList()), RealURI(URI),
MetaIndexParser(MetaIndexParser), MetaIndexFile(MetaIndexFile),
- IndexTargets(IndexTargets), AuthPass(false)
+ IndexTargets(IndexTargets), AuthPass(false), IMSHit(false)
{
DestFile = _config->FindDir("Dir::State::lists") + "partial/";
DestFile += URItoFileName(URI);
- TransactionID = (unsigned long)MetaOwner;
-
// remove any partial downloaded sig-file in partial/.
// it may confuse proxies and is too small to warrant a
// partial download anyway
unlink(DestFile.c_str());
+ // set the TransactionID
+ TransactionID = (unsigned long)MetaOwner;
+
// Create the item
Desc.Description = URIDesc;
Desc.Owner = this;
Desc.ShortDesc = ShortDesc;
Desc.URI = URI;
-#if 0
- string Final = _config->FindDir("Dir::State::lists");
- Final += URItoFileName(RealURI);
- if (RealFileExists(Final) == true)
- {
- // File was already in place. It needs to be re-downloaded/verified
- // because Release might have changed, we do give it a different
- // name than DestFile because otherwise the http method will
- // send If-Range requests and there are too many broken servers
- // out there that do not understand them
- LastGoodSig = DestFile+".reverify";
- Rename(Final,LastGoodSig);
- }
-#endif
- // we expect the indextargets + one additional Release file
- //ExpectedAdditionalItems = IndexTargets->size() + 1;
-
QueueURI(Desc);
}
/*}}}*/
pkgAcqMetaSig::~pkgAcqMetaSig() /*{{{*/
{
- // if the file was never queued undo file-changes done in the constructor
- if (QueueCounter == 1 && Status == StatIdle && FileSize == 0 && Complete == false &&
- LastGoodSig.empty() == false)
- {
- string const Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
- if (RealFileExists(Final) == false && RealFileExists(LastGoodSig) == true)
- Rename(LastGoodSig, Final);
- }
-
}
/*}}}*/
// pkgAcqMetaSig::Custom600Headers - Insert custom request headers /*{{{*/
@@ -1378,8 +1353,11 @@ pkgAcqMetaSig::~pkgAcqMetaSig() /*{{{*/
/* The only header we use is the last-modified header. */
string pkgAcqMetaSig::Custom600Headers() const
{
+ string FinalFile = _config->FindDir("Dir::State::lists");
+ FinalFile += URItoFileName(RealURI);
+
struct stat Buf;
- if (stat(LastGoodSig.c_str(),&Buf) != 0)
+ if (stat(FinalFile.c_str(),&Buf) != 0)
return "\nIndex-File: true";
return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
@@ -1407,6 +1385,18 @@ void pkgAcqMetaSig::Done(string Message,unsigned long long Size, HashStringList
return;
}
+ if(StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
+ IMSHit = true;
+
+ // adjust paths if its a ims-hit
+ if(IMSHit)
+ {
+ string FinalFile = _config->FindDir("Dir::State::lists");
+ FinalFile += URItoFileName(RealURI);
+
+ DestFile = PartialFile = FinalFile;
+ }
+
// queue for verify
if(AuthPass == false)
{
@@ -1417,65 +1407,31 @@ void pkgAcqMetaSig::Done(string Message,unsigned long long Size, HashStringList
return;
}
- Complete = true;
-
- // put the last known good file back on i-m-s hit (it will
- // be re-verified again)
- // Else do nothing, we have the new file in DestFile then
- if(StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
- Rename(LastGoodSig, DestFile);
-
- // queue for copy
- PartialFile = _config->FindDir("Dir::State::lists") + "partial/";
- PartialFile += URItoFileName(RealURI);
-
- DestFile = _config->FindDir("Dir::State::lists");
- DestFile += URItoFileName(RealURI);
+ // queue to copy the file in place if it was not a ims hit, on ims
+ // hit the file is already at the right place
+ if(IMSHit == false)
+ {
+ PartialFile = _config->FindDir("Dir::State::lists") + "partial/";
+ PartialFile += URItoFileName(RealURI);
+
+ DestFile = _config->FindDir("Dir::State::lists");
+ DestFile += URItoFileName(RealURI);
+ }
-#if 0
- // queue a pkgAcqMetaIndex to be verified against the sig we just retrieved
- pkgAcqMetaIndex *metaindex = new pkgAcqMetaIndex(
- Owner, MetaIndexURI, MetaIndexURIDesc,
- MetaIndexShortDesc, DestFile, IndexTargets,
- MetaIndexParser);
+ Complete = true;
- TransactionID = (unsigned long)metaindex;
-#endif
}
/*}}}*/
void pkgAcqMetaSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf)/*{{{*/
{
string Final = _config->FindDir("Dir::State::lists") + URItoFileName(RealURI);
- // if we get a network error we fail gracefully
- if(Status == StatTransientNetworkError)
- {
- Item::Failed(Message,Cnf);
- // move the sigfile back on transient network failures
- if(FileExists(LastGoodSig))
- Rename(LastGoodSig,Final);
- // set the status back to , Item::Failed likes to reset it
- Status = pkgAcquire::Item::StatTransientNetworkError;
- return;
- }
+ // this ensures that any file in the lists/ dir is removed by the
+ // transaction
+ DestFile = _config->FindDir("Dir::State::lists") + "partial/";
+ DestFile += URItoFileName(RealURI);
+ PartialFile = "";
- // Delete any existing sigfile when the acquire failed
- unlink(Final.c_str());
-#if 0
- // queue a pkgAcqMetaIndex with no sigfile
- new pkgAcqMetaIndex(Owner, MetaIndexURI, MetaIndexURIDesc, MetaIndexShortDesc,
- "", IndexTargets, MetaIndexParser);
-#endif
- if (Cnf->LocalOnly == true ||
- StringToBool(LookupTag(Message,"Transient-Failure"),false) == false)
- {
- // Ignore this
- Status = StatDone;
- Complete = false;
- Dequeue();
- return;
- }
-
Item::Failed(Message,Cnf);
}
/*}}}*/
@@ -1582,6 +1538,7 @@ void pkgAcqMetaIndex::Done(string Message,unsigned long long Size,HashStringList
FinalFile += URItoFileName(RealURI);
if (SigFile == DestFile)
SigFile = FinalFile;
+ // queue for copy in place
PartialFile = DestFile;
DestFile = FinalFile;
}
diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h
index 6235c353b..11a596ad5 100644
--- a/apt-pkg/acquire-item.h
+++ b/apt-pkg/acquire-item.h
@@ -1031,9 +1031,12 @@ class pkgAcqMetaSig : public pkgAcquire::Item
*/
const std::vector<IndexTarget*>* IndexTargets;
- /** \brief if we are in fetching or download state */
+ /** \brief If we are in fetching or download state */
bool AuthPass;
+ /** \brief Was this file already on disk */
+ bool IMSHit;
+
public:
// Specialized action members
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index 4b82fa46d..b14a54f0f 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -222,7 +222,6 @@ void pkgAcquire::CommitTransaction(unsigned long TransactionID)
std::clog << "mv "
<< (*I)->PartialFile << " -> "
<< (*I)->DestFile << std::endl;
-
Rename((*I)->PartialFile, (*I)->DestFile);
chmod((*I)->DestFile.c_str(),0644);
} else {