1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acquire-item.cc,v 1.46.2.9 2004/01/16 18:51:11 mdz Exp $
4 /* ######################################################################
6 Acquire Item - Item to acquire
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.
13 ##################################################################### */
15 // Include Files /*{{{*/
18 #include <apt-pkg/acquire-item.h>
19 #include <apt-pkg/configuration.h>
20 #include <apt-pkg/aptconfiguration.h>
21 #include <apt-pkg/sourcelist.h>
22 #include <apt-pkg/error.h>
23 #include <apt-pkg/strutl.h>
24 #include <apt-pkg/fileutl.h>
25 #include <apt-pkg/sha1.h>
26 #include <apt-pkg/tagfile.h>
27 #include <apt-pkg/indexrecords.h>
28 #include <apt-pkg/acquire.h>
29 #include <apt-pkg/hashes.h>
30 #include <apt-pkg/indexfile.h>
31 #include <apt-pkg/pkgcache.h>
32 #include <apt-pkg/cacheiterators.h>
33 #include <apt-pkg/pkgrecords.h>
53 static void printHashSumComparision(std::string
const &URI
, HashStringList
const &Expected
, HashStringList
const &Actual
) /*{{{*/
55 if (_config
->FindB("Debug::Acquire::HashSumMismatch", false) == false)
57 std::cerr
<< std::endl
<< URI
<< ":" << std::endl
<< " Expected Hash: " << std::endl
;
58 for (HashStringList::const_iterator hs
= Expected
.begin(); hs
!= Expected
.end(); ++hs
)
59 std::cerr
<< "\t- " << hs
->toStr() << std::endl
;
60 std::cerr
<< " Actual Hash: " << std::endl
;
61 for (HashStringList::const_iterator hs
= Actual
.begin(); hs
!= Actual
.end(); ++hs
)
62 std::cerr
<< "\t- " << hs
->toStr() << std::endl
;
65 static std::string
GetPartialFileName(std::string
const &file
) /*{{{*/
67 std::string DestFile
= _config
->FindDir("Dir::State::lists") + "partial/";
72 static std::string
GetPartialFileNameFromURI(std::string
const &uri
) /*{{{*/
74 return GetPartialFileName(URItoFileName(uri
));
77 static std::string
GetFinalFileNameFromURI(std::string
const &uri
) /*{{{*/
79 return _config
->FindDir("Dir::State::lists") + URItoFileName(uri
);
82 static std::string
GetCompressedFileName(std::string
const &URI
, std::string
const &Name
, std::string
const &Ext
) /*{{{*/
84 if (Ext
.empty() || Ext
== "uncompressed")
87 // do not reverify cdrom sources as apt-cdrom may rewrite the Packages
88 // file when its doing the indexcopy
89 if (URI
.substr(0,6) == "cdrom:")
92 // adjust DestFile if its compressed on disk
93 if (_config
->FindB("Acquire::GzipIndexes",false) == true)
94 return Name
+ '.' + Ext
;
98 static std::string
GetMergeDiffsPatchFileName(std::string
const &Final
, std::string
const &Patch
)/*{{{*/
100 // rred expects the patch as $FinalFile.ed.$patchname.gz
101 return Final
+ ".ed." + Patch
+ ".gz";
104 static std::string
GetDiffsPatchFileName(std::string
const &Final
) /*{{{*/
106 // rred expects the patch as $FinalFile.ed
107 return Final
+ ".ed";
111 static bool AllowInsecureRepositories(indexRecords
const * const MetaIndexParser
, pkgAcqMetaBase
* const TransactionManager
, pkgAcquire::Item
* const I
) /*{{{*/
113 if(MetaIndexParser
->IsAlwaysTrusted() || _config
->FindB("Acquire::AllowInsecureRepositories") == true)
116 _error
->Error(_("Use --allow-insecure-repositories to force the update"));
117 TransactionManager
->AbortTransaction();
118 I
->Status
= pkgAcquire::Item::StatError
;
122 static HashStringList
GetExpectedHashesFromFor(indexRecords
* const Parser
, std::string
const MetaKey
)/*{{{*/
125 return HashStringList();
126 indexRecords::checkSum
* const R
= Parser
->Lookup(MetaKey
);
128 return HashStringList();
133 // all ::HashesRequired and ::GetExpectedHashes implementations /*{{{*/
134 /* ::GetExpectedHashes is abstract and has to be implemented by all subclasses.
135 It is best to implement it as broadly as possible, while ::HashesRequired defaults
136 to true and should be as restrictive as possible for false cases. Note that if
137 a hash is returned by ::GetExpectedHashes it must match. Only if it doesn't
138 ::HashesRequired is called to evaluate if its okay to have no hashes. */
139 APT_CONST
bool pkgAcqTransactionItem::HashesRequired() const
141 /* signed repositories obviously have a parser and good hashes.
142 unsigned repositories, too, as even if we can't trust them for security,
143 we can at least trust them for integrity of the download itself.
144 Only repositories without a Release file can (obviously) not have
145 hashes – and they are very uncommon and strongly discouraged */
146 return TransactionManager
->MetaIndexParser
!= NULL
;
148 HashStringList
pkgAcqTransactionItem::GetExpectedHashes() const
150 return GetExpectedHashesFor(GetMetaKey());
153 APT_CONST
bool pkgAcqMetaBase::HashesRequired() const
155 // Release and co have no hashes 'by design'.
158 HashStringList
pkgAcqMetaBase::GetExpectedHashes() const
160 return HashStringList();
163 APT_CONST
bool pkgAcqIndexDiffs::HashesRequired() const
165 /* We don't always have the diff of the downloaded pdiff file.
166 What we have for sure is hashes for the uncompressed file,
167 but rred uncompresses them on the fly while parsing, so not handled here.
168 Hashes are (also) checked while searching for (next) patch to apply. */
169 if (State
== StateFetchDiff
)
170 return available_patches
[0].download_hashes
.empty() == false;
173 HashStringList
pkgAcqIndexDiffs::GetExpectedHashes() const
175 if (State
== StateFetchDiff
)
176 return available_patches
[0].download_hashes
;
177 return HashStringList();
180 APT_CONST
bool pkgAcqIndexMergeDiffs::HashesRequired() const
182 /* @see #pkgAcqIndexDiffs::HashesRequired, with the difference that
183 we can check the rred result after all patches are applied as
184 we know the expected result rather than potentially apply more patches */
185 if (State
== StateFetchDiff
)
186 return patch
.download_hashes
.empty() == false;
187 return State
== StateApplyDiff
;
189 HashStringList
pkgAcqIndexMergeDiffs::GetExpectedHashes() const
191 if (State
== StateFetchDiff
)
192 return patch
.download_hashes
;
193 else if (State
== StateApplyDiff
)
194 return GetExpectedHashesFor(Target
.MetaKey
);
195 return HashStringList();
198 APT_CONST
bool pkgAcqArchive::HashesRequired() const
200 return LocalSource
== false;
202 HashStringList
pkgAcqArchive::GetExpectedHashes() const
204 // figured out while parsing the records
205 return ExpectedHashes
;
208 APT_CONST
bool pkgAcqFile::HashesRequired() const
210 // supplied as parameter at creation time, so the caller decides
211 return ExpectedHashes
.usable();
213 HashStringList
pkgAcqFile::GetExpectedHashes() const
215 return ExpectedHashes
;
218 // Acquire::Item::QueueURI and specialisations from child classes /*{{{*/
219 bool pkgAcquire::Item::QueueURI(pkgAcquire::ItemDesc
&Item
)
221 Owner
->Enqueue(Item
);
224 /* The idea here is that an item isn't queued if it exists on disk and the
225 transition manager was a hit as this means that the files it contains
226 the checksums for can't be updated either (or they are and we are asking
227 for a hashsum mismatch to happen which helps nobody) */
228 bool pkgAcqTransactionItem::QueueURI(pkgAcquire::ItemDesc
&Item
)
230 std::string
const FinalFile
= GetFinalFilename();
231 if (TransactionManager
!= NULL
&& TransactionManager
->IMSHit
== true &&
232 FileExists(FinalFile
) == true)
234 PartialFile
= DestFile
= FinalFile
;
238 return pkgAcquire::Item::QueueURI(Item
);
240 /* The transition manager InRelease itself (or its older sisters-in-law
241 Release & Release.gpg) is always queued as this allows us to rerun gpgv
242 on it to verify that we aren't stalled with old files */
243 bool pkgAcqMetaBase::QueueURI(pkgAcquire::ItemDesc
&Item
)
245 return pkgAcquire::Item::QueueURI(Item
);
247 /* the Diff/Index needs to queue also the up-to-date complete index file
248 to ensure that the list cleaner isn't eating it */
249 bool pkgAcqDiffIndex::QueueURI(pkgAcquire::ItemDesc
&Item
)
251 if (pkgAcqTransactionItem::QueueURI(Item
) == true)
257 // Acquire::Item::GetFinalFilename and specialisations for child classes /*{{{*/
258 std::string
pkgAcquire::Item::GetFinalFilename() const
260 return GetFinalFileNameFromURI(Desc
.URI
);
262 std::string
pkgAcqDiffIndex::GetFinalFilename() const
264 // the logic we inherent from pkgAcqBaseIndex isn't what we need here
265 return pkgAcquire::Item::GetFinalFilename();
267 std::string
pkgAcqIndex::GetFinalFilename() const
269 std::string
const FinalFile
= GetFinalFileNameFromURI(Target
.URI
);
270 return GetCompressedFileName(Target
.URI
, FinalFile
, CurrentCompressionExtension
);
272 std::string
pkgAcqMetaSig::GetFinalFilename() const
274 return GetFinalFileNameFromURI(Target
.URI
);
276 std::string
pkgAcqBaseIndex::GetFinalFilename() const
278 return GetFinalFileNameFromURI(Target
.URI
);
280 std::string
pkgAcqMetaBase::GetFinalFilename() const
282 return GetFinalFileNameFromURI(Target
.URI
);
284 std::string
pkgAcqArchive::GetFinalFilename() const
286 return _config
->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename
);
289 // pkgAcqTransactionItem::GetMetaKey and specialisations for child classes /*{{{*/
290 std::string
pkgAcqTransactionItem::GetMetaKey() const
292 return Target
.MetaKey
;
294 std::string
pkgAcqIndex::GetMetaKey() const
296 if (Stage
== STAGE_DECOMPRESS_AND_VERIFY
|| CurrentCompressionExtension
== "uncompressed")
297 return Target
.MetaKey
;
298 return Target
.MetaKey
+ "." + CurrentCompressionExtension
;
300 std::string
pkgAcqDiffIndex::GetMetaKey() const
302 return Target
.MetaKey
+ ".diff/Index";
305 //pkgAcqTransactionItem::TransactionState and specialisations for child classes /*{{{*/
306 bool pkgAcqTransactionItem::TransactionState(TransactionStates
const state
)
308 bool const Debug
= _config
->FindB("Debug::Acquire::Transaction", false);
311 case TransactionAbort
:
313 std::clog
<< " Cancel: " << DestFile
<< std::endl
;
314 if (Status
== pkgAcquire::Item::StatIdle
)
316 Status
= pkgAcquire::Item::StatDone
;
320 case TransactionCommit
:
321 if(PartialFile
!= "")
324 std::clog
<< "mv " << PartialFile
<< " -> "<< DestFile
<< " # " << DescURI() << std::endl
;
326 Rename(PartialFile
, DestFile
);
329 std::clog
<< "rm " << DestFile
<< " # " << DescURI() << std::endl
;
330 unlink(DestFile
.c_str());
336 bool pkgAcqMetaBase::TransactionState(TransactionStates
const state
)
338 // Do not remove InRelease on IMSHit of Release.gpg [yes, this is very edgecasey]
339 if (TransactionManager
->IMSHit
== false)
340 return pkgAcqTransactionItem::TransactionState(state
);
343 bool pkgAcqIndex::TransactionState(TransactionStates
const state
)
345 if (pkgAcqTransactionItem::TransactionState(state
) == false)
350 case TransactionAbort
:
351 if (Stage
== STAGE_DECOMPRESS_AND_VERIFY
)
353 // keep the compressed file, but drop the decompressed
354 EraseFileName
.clear();
355 if (PartialFile
.empty() == false && flExtension(PartialFile
) == "decomp")
356 unlink(PartialFile
.c_str());
359 case TransactionCommit
:
360 if (EraseFileName
.empty() == false)
361 unlink(EraseFileName
.c_str());
366 bool pkgAcqDiffIndex::TransactionState(TransactionStates
const state
)
368 if (pkgAcqTransactionItem::TransactionState(state
) == false)
373 case TransactionCommit
:
375 case TransactionAbort
:
376 std::string
const Partial
= GetPartialFileNameFromURI(Target
.URI
);
377 unlink(Partial
.c_str());
385 // IndexTarget - Constructor /*{{{*/
386 IndexTarget::IndexTarget(std::string
const &MetaKey
, std::string
const &ShortDesc
,
387 std::string
const &LongDesc
, std::string
const &URI
, bool const IsOptional
,
388 std::map
<std::string
, std::string
> const &Options
) :
389 URI(URI
), Description(LongDesc
), ShortDesc(ShortDesc
), MetaKey(MetaKey
), IsOptional(IsOptional
), Options(Options
)
394 class APT_HIDDEN NoActionItem
: public pkgAcquire::Item
/*{{{*/
395 /* The sole purpose of this class is having an item which does nothing to
396 reach its done state to prevent cleanup deleting the mentioned file.
397 Handy in cases in which we know we have the file already, like IMS-Hits. */
399 IndexTarget
const Target
;
401 virtual std::string
DescURI() const {return Target
.URI
;};
402 virtual HashStringList
GetExpectedHashes() const {return HashStringList();};
404 NoActionItem(pkgAcquire
* const Owner
, IndexTarget
const Target
) :
405 pkgAcquire::Item(Owner
), Target(Target
)
408 DestFile
= GetFinalFileNameFromURI(Target
.URI
);
413 // Acquire::Item::Item - Constructor /*{{{*/
414 APT_IGNORE_DEPRECATED_PUSH
415 pkgAcquire::Item::Item(pkgAcquire
* const Owner
) :
416 FileSize(0), PartialSize(0), Mode(0), Complete(false), Local(false),
417 QueueCounter(0), ExpectedAdditionalItems(0), Owner(Owner
)
422 APT_IGNORE_DEPRECATED_POP
424 // Acquire::Item::~Item - Destructor /*{{{*/
425 pkgAcquire::Item::~Item()
430 std::string
pkgAcquire::Item::Custom600Headers() const /*{{{*/
432 return std::string();
435 std::string
pkgAcquire::Item::ShortDesc() const /*{{{*/
440 APT_CONST
void pkgAcquire::Item::Finished() /*{{{*/
444 APT_PURE pkgAcquire
* pkgAcquire::Item::GetOwner() const /*{{{*/
449 APT_CONST
bool pkgAcquire::Item::IsTrusted() const /*{{{*/
454 // Acquire::Item::Failed - Item failed to download /*{{{*/
455 // ---------------------------------------------------------------------
456 /* We return to an idle state if there are still other queues that could
458 void pkgAcquire::Item::Failed(string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
)
460 if(ErrorText
.empty())
461 ErrorText
= LookupTag(Message
,"Message");
462 UsedMirror
= LookupTag(Message
,"UsedMirror");
463 if (QueueCounter
<= 1)
465 /* This indicates that the file is not available right now but might
466 be sometime later. If we do a retry cycle then this should be
468 if (Cnf
!= NULL
&& Cnf
->LocalOnly
== true &&
469 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
485 case StatTransientNetworkError
:
492 string
const FailReason
= LookupTag(Message
, "FailReason");
493 if (FailReason
== "MaximumSizeExceeded")
494 RenameOnError(MaximumSizeExceeded
);
495 else if (Status
== StatAuthError
)
496 RenameOnError(HashSumMismatch
);
498 // report mirror failure back to LP if we actually use a mirror
499 if (FailReason
.empty() == false)
500 ReportMirrorFailure(FailReason
);
502 ReportMirrorFailure(ErrorText
);
504 if (QueueCounter
> 1)
508 // Acquire::Item::Start - Item has begun to download /*{{{*/
509 // ---------------------------------------------------------------------
510 /* Stash status and the file size. Note that setting Complete means
511 sub-phases of the acquire process such as decompresion are operating */
512 void pkgAcquire::Item::Start(string
const &/*Message*/, unsigned long long const Size
)
514 Status
= StatFetching
;
516 if (FileSize
== 0 && Complete
== false)
520 // Acquire::Item::Done - Item downloaded OK /*{{{*/
521 void pkgAcquire::Item::Done(string
const &Message
, HashStringList
const &Hashes
,
522 pkgAcquire::MethodConfig
const * const /*Cnf*/)
524 // We just downloaded something..
525 string FileName
= LookupTag(Message
,"Filename");
526 UsedMirror
= LookupTag(Message
,"UsedMirror");
527 unsigned long long const downloadedSize
= Hashes
.FileSize();
528 if (downloadedSize
!= 0)
530 if (Complete
== false && !Local
&& FileName
== DestFile
)
533 Owner
->Log
->Fetched(Hashes
.FileSize(),atoi(LookupTag(Message
,"Resume-Point","0").c_str()));
537 FileSize
= downloadedSize
;
540 ErrorText
= string();
541 Owner
->Dequeue(this);
544 // Acquire::Item::Rename - Rename a file /*{{{*/
545 // ---------------------------------------------------------------------
546 /* This helper function is used by a lot of item methods as their final
548 bool pkgAcquire::Item::Rename(string
const &From
,string
const &To
)
550 if (From
== To
|| rename(From
.c_str(),To
.c_str()) == 0)
554 strprintf(S
, _("rename failed, %s (%s -> %s)."), strerror(errno
),
555 From
.c_str(),To
.c_str());
557 if (ErrorText
.empty())
560 ErrorText
= ErrorText
+ ": " + S
;
564 void pkgAcquire::Item::Dequeue() /*{{{*/
566 Owner
->Dequeue(this);
569 bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState
const error
)/*{{{*/
571 if (RealFileExists(DestFile
))
572 Rename(DestFile
, DestFile
+ ".FAILED");
577 case HashSumMismatch
:
578 errtext
= _("Hash Sum mismatch");
579 Status
= StatAuthError
;
580 ReportMirrorFailure("HashChecksumFailure");
583 errtext
= _("Size mismatch");
584 Status
= StatAuthError
;
585 ReportMirrorFailure("SizeFailure");
588 errtext
= _("Invalid file format");
590 // do not report as usually its not the mirrors fault, but Portal/Proxy
593 errtext
= _("Signature error");
597 errtext
= _("Does not start with a cleartext signature");
600 case MaximumSizeExceeded
:
601 // the method is expected to report a good error for this
605 // no handling here, done by callers
608 if (ErrorText
.empty())
613 void pkgAcquire::Item::SetActiveSubprocess(const std::string
&subprocess
)/*{{{*/
615 ActiveSubprocess
= subprocess
;
616 APT_IGNORE_DEPRECATED(Mode
= ActiveSubprocess
.c_str();)
619 // Acquire::Item::ReportMirrorFailure /*{{{*/
620 void pkgAcquire::Item::ReportMirrorFailure(string
const &FailCode
)
622 // we only act if a mirror was used at all
623 if(UsedMirror
.empty())
626 std::cerr
<< "\nReportMirrorFailure: "
628 << " Uri: " << DescURI()
630 << FailCode
<< std::endl
;
632 string report
= _config
->Find("Methods::Mirror::ProblemReporting",
633 "/usr/lib/apt/apt-report-mirror-failure");
634 if(!FileExists(report
))
637 std::vector
<char const*> Args
;
638 Args
.push_back(report
.c_str());
639 Args
.push_back(UsedMirror
.c_str());
640 Args
.push_back(DescURI().c_str());
641 Args
.push_back(FailCode
.c_str());
642 Args
.push_back(NULL
);
644 pid_t pid
= ExecFork();
647 _error
->Error("ReportMirrorFailure Fork failed");
652 execvp(Args
[0], (char**)Args
.data());
653 std::cerr
<< "Could not exec " << Args
[0] << std::endl
;
656 if(!ExecWait(pid
, "report-mirror-failure"))
658 _error
->Warning("Couldn't report problem to '%s'",
659 _config
->Find("Methods::Mirror::ProblemReporting").c_str());
663 std::string
pkgAcquire::Item::HashSum() const /*{{{*/
665 HashStringList
const hashes
= GetExpectedHashes();
666 HashString
const * const hs
= hashes
.find(NULL
);
667 return hs
!= NULL
? hs
->toStr() : "";
671 pkgAcqTransactionItem::pkgAcqTransactionItem(pkgAcquire
* const Owner
, /*{{{*/
672 pkgAcqMetaBase
* const TransactionManager
, IndexTarget
const Target
) :
673 pkgAcquire::Item(Owner
), Target(Target
), TransactionManager(TransactionManager
)
675 if (TransactionManager
!= this)
676 TransactionManager
->Add(this);
679 pkgAcqTransactionItem::~pkgAcqTransactionItem() /*{{{*/
683 HashStringList
pkgAcqTransactionItem::GetExpectedHashesFor(std::string
const MetaKey
) const /*{{{*/
685 return GetExpectedHashesFromFor(TransactionManager
->MetaIndexParser
, MetaKey
);
689 // AcqMetaBase - Constructor /*{{{*/
690 pkgAcqMetaBase::pkgAcqMetaBase(pkgAcquire
* const Owner
,
691 pkgAcqMetaBase
* const TransactionManager
,
692 std::vector
<IndexTarget
> const IndexTargets
,
693 IndexTarget
const &DataTarget
,
694 indexRecords
* const MetaIndexParser
)
695 : pkgAcqTransactionItem(Owner
, TransactionManager
, DataTarget
),
696 MetaIndexParser(MetaIndexParser
), LastMetaIndexParser(NULL
), IndexTargets(IndexTargets
),
697 AuthPass(false), IMSHit(false)
701 // AcqMetaBase::Add - Add a item to the current Transaction /*{{{*/
702 void pkgAcqMetaBase::Add(pkgAcqTransactionItem
* const I
)
704 Transaction
.push_back(I
);
707 // AcqMetaBase::AbortTransaction - Abort the current Transaction /*{{{*/
708 void pkgAcqMetaBase::AbortTransaction()
710 if(_config
->FindB("Debug::Acquire::Transaction", false) == true)
711 std::clog
<< "AbortTransaction: " << TransactionManager
<< std::endl
;
713 // ensure the toplevel is in error state too
714 for (std::vector
<pkgAcqTransactionItem
*>::iterator I
= Transaction
.begin();
715 I
!= Transaction
.end(); ++I
)
717 (*I
)->TransactionState(TransactionAbort
);
722 // AcqMetaBase::TransactionHasError - Check for errors in Transaction /*{{{*/
723 APT_PURE
bool pkgAcqMetaBase::TransactionHasError() const
725 for (std::vector
<pkgAcqTransactionItem
*>::const_iterator I
= Transaction
.begin();
726 I
!= Transaction
.end(); ++I
)
728 switch((*I
)->Status
) {
729 case StatDone
: break;
730 case StatIdle
: break;
731 case StatAuthError
: return true;
732 case StatError
: return true;
733 case StatTransientNetworkError
: return true;
734 case StatFetching
: break;
740 // AcqMetaBase::CommitTransaction - Commit a transaction /*{{{*/
741 void pkgAcqMetaBase::CommitTransaction()
743 if(_config
->FindB("Debug::Acquire::Transaction", false) == true)
744 std::clog
<< "CommitTransaction: " << this << std::endl
;
746 // move new files into place *and* remove files that are not
747 // part of the transaction but are still on disk
748 for (std::vector
<pkgAcqTransactionItem
*>::iterator I
= Transaction
.begin();
749 I
!= Transaction
.end(); ++I
)
751 (*I
)->TransactionState(TransactionCommit
);
756 // AcqMetaBase::TransactionStageCopy - Stage a file for copying /*{{{*/
757 void pkgAcqMetaBase::TransactionStageCopy(pkgAcqTransactionItem
* const I
,
758 const std::string
&From
,
759 const std::string
&To
)
761 I
->PartialFile
= From
;
765 // AcqMetaBase::TransactionStageRemoval - Stage a file for removal /*{{{*/
766 void pkgAcqMetaBase::TransactionStageRemoval(pkgAcqTransactionItem
* const I
,
767 const std::string
&FinalFile
)
770 I
->DestFile
= FinalFile
;
773 // AcqMetaBase::GenerateAuthWarning - Check gpg authentication error /*{{{*/
774 bool pkgAcqMetaBase::CheckStopAuthentication(pkgAcquire::Item
* const I
, const std::string
&Message
)
776 // FIXME: this entire function can do now that we disallow going to
777 // a unauthenticated state and can cleanly rollback
779 string
const Final
= I
->GetFinalFilename();
780 if(FileExists(Final
))
782 I
->Status
= StatTransientNetworkError
;
783 _error
->Warning(_("An error occurred during the signature "
784 "verification. The repository is not updated "
785 "and the previous index files will be used. "
786 "GPG error: %s: %s\n"),
787 Desc
.Description
.c_str(),
788 LookupTag(Message
,"Message").c_str());
789 RunScripts("APT::Update::Auth-Failure");
791 } else if (LookupTag(Message
,"Message").find("NODATA") != string::npos
) {
792 /* Invalid signature file, reject (LP: #346386) (Closes: #627642) */
793 _error
->Error(_("GPG error: %s: %s"),
794 Desc
.Description
.c_str(),
795 LookupTag(Message
,"Message").c_str());
796 I
->Status
= StatError
;
799 _error
->Warning(_("GPG error: %s: %s"),
800 Desc
.Description
.c_str(),
801 LookupTag(Message
,"Message").c_str());
803 // gpgv method failed
804 ReportMirrorFailure("GPGFailure");
808 // AcqMetaBase::Custom600Headers - Get header for AcqMetaBase /*{{{*/
809 // ---------------------------------------------------------------------
810 string
pkgAcqMetaBase::Custom600Headers() const
812 std::string Header
= "\nIndex-File: true";
813 std::string MaximumSize
;
814 strprintf(MaximumSize
, "\nMaximum-Size: %i",
815 _config
->FindI("Acquire::MaxReleaseFileSize", 10*1000*1000));
816 Header
+= MaximumSize
;
818 string
const FinalFile
= GetFinalFilename();
821 if (stat(FinalFile
.c_str(),&Buf
) == 0)
822 Header
+= "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
827 // AcqMetaBase::QueueForSignatureVerify /*{{{*/
828 void pkgAcqMetaBase::QueueForSignatureVerify(pkgAcqTransactionItem
* const I
, std::string
const &File
, std::string
const &Signature
)
831 I
->Desc
.URI
= "gpgv:" + Signature
;
834 I
->SetActiveSubprocess("gpgv");
837 // AcqMetaBase::CheckDownloadDone /*{{{*/
838 bool pkgAcqMetaBase::CheckDownloadDone(pkgAcqTransactionItem
* const I
, const std::string
&Message
, HashStringList
const &Hashes
) const
840 // We have just finished downloading a Release file (it is not
843 string
const FileName
= LookupTag(Message
,"Filename");
844 if (FileName
.empty() == true)
846 I
->Status
= StatError
;
847 I
->ErrorText
= "Method gave a blank filename";
851 if (FileName
!= I
->DestFile
)
854 I
->Desc
.URI
= "copy:" + FileName
;
855 I
->QueueURI(I
->Desc
);
859 // make sure to verify against the right file on I-M-S hit
860 bool IMSHit
= StringToBool(LookupTag(Message
,"IMS-Hit"), false);
861 if (IMSHit
== false && Hashes
.usable())
863 // detect IMS-Hits servers haven't detected by Hash comparison
864 std::string
const FinalFile
= I
->GetFinalFilename();
865 if (RealFileExists(FinalFile
) && Hashes
.VerifyFile(FinalFile
) == true)
868 unlink(I
->DestFile
.c_str());
874 // for simplicity, the transaction manager is always InRelease
875 // even if it doesn't exist.
876 if (TransactionManager
!= NULL
)
877 TransactionManager
->IMSHit
= true;
878 I
->PartialFile
= I
->DestFile
= I
->GetFinalFilename();
881 // set Item to complete as the remaining work is all local (verify etc)
887 bool pkgAcqMetaBase::CheckAuthDone(string
const &Message
) /*{{{*/
889 // At this point, the gpgv method has succeeded, so there is a
890 // valid signature from a key in the trusted keyring. We
891 // perform additional verification of its contents, and use them
892 // to verify the indexes we are about to download
894 if (TransactionManager
->IMSHit
== false)
896 // open the last (In)Release if we have it
897 std::string
const FinalFile
= GetFinalFilename();
898 std::string FinalRelease
;
899 std::string FinalInRelease
;
900 if (APT::String::Endswith(FinalFile
, "InRelease"))
902 FinalInRelease
= FinalFile
;
903 FinalRelease
= FinalFile
.substr(0, FinalFile
.length() - strlen("InRelease")) + "Release";
907 FinalInRelease
= FinalFile
.substr(0, FinalFile
.length() - strlen("Release")) + "InRelease";
908 FinalRelease
= FinalFile
;
910 if (RealFileExists(FinalInRelease
) || RealFileExists(FinalRelease
))
912 TransactionManager
->LastMetaIndexParser
= new indexRecords
;
913 _error
->PushToStack();
914 if (RealFileExists(FinalInRelease
))
915 TransactionManager
->LastMetaIndexParser
->Load(FinalInRelease
);
917 TransactionManager
->LastMetaIndexParser
->Load(FinalRelease
);
918 // its unlikely to happen, but if what we have is bad ignore it
919 if (_error
->PendingError())
921 delete TransactionManager
->LastMetaIndexParser
;
922 TransactionManager
->LastMetaIndexParser
= NULL
;
924 _error
->RevertToStack();
928 if (TransactionManager
->MetaIndexParser
->Load(DestFile
) == false)
930 Status
= StatAuthError
;
931 ErrorText
= TransactionManager
->MetaIndexParser
->ErrorText
;
935 if (!VerifyVendor(Message
))
937 Status
= StatAuthError
;
941 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
942 std::cerr
<< "Signature verification succeeded: "
943 << DestFile
<< std::endl
;
945 // Download further indexes with verification
951 void pkgAcqMetaBase::QueueIndexes(bool const verify
) /*{{{*/
953 // at this point the real Items are loaded in the fetcher
954 ExpectedAdditionalItems
= 0;
956 for (std::vector
<IndexTarget
>::const_iterator Target
= IndexTargets
.begin();
957 Target
!= IndexTargets
.end();
960 bool trypdiff
= _config
->FindB("Acquire::PDiffs", true);
963 if (TransactionManager
->MetaIndexParser
->Exists(Target
->MetaKey
) == false)
965 // optional targets that we do not have in the Release file are skipped
966 if (Target
->IsOptional
)
969 Status
= StatAuthError
;
970 strprintf(ErrorText
, _("Unable to find expected entry '%s' in Release file (Wrong sources.list entry or malformed file)"), Target
->MetaKey
.c_str());
974 if (RealFileExists(GetFinalFileNameFromURI(Target
->URI
)))
976 if (TransactionManager
->LastMetaIndexParser
!= NULL
)
978 HashStringList
const newFile
= GetExpectedHashesFromFor(TransactionManager
->MetaIndexParser
, Target
->MetaKey
);
979 HashStringList
const oldFile
= GetExpectedHashesFromFor(TransactionManager
->LastMetaIndexParser
, Target
->MetaKey
);
980 if (newFile
== oldFile
)
982 // we have the file already, no point in trying to acquire it again
983 new NoActionItem(Owner
, *Target
);
989 trypdiff
= false; // no file to patch
991 // check if we have patches available
992 trypdiff
&= TransactionManager
->MetaIndexParser
->Exists(Target
->MetaKey
+ ".diff/Index");
994 // if we have no file to patch, no point in trying
995 trypdiff
&= RealFileExists(GetFinalFileNameFromURI(Target
->URI
));
997 // no point in patching from local sources
1000 std::string
const proto
= Target
->URI
.substr(0, strlen("file:/"));
1001 if (proto
== "file:/" || proto
== "copy:/" || proto
== "cdrom:")
1005 // Queue the Index file (Packages, Sources, Translation-$foo, …)
1007 new pkgAcqDiffIndex(Owner
, TransactionManager
, *Target
);
1009 new pkgAcqIndex(Owner
, TransactionManager
, *Target
);
1013 bool pkgAcqMetaBase::VerifyVendor(string
const &Message
) /*{{{*/
1015 string::size_type pos
;
1017 // check for missing sigs (that where not fatal because otherwise we had
1020 string msg
= _("There is no public key available for the "
1021 "following key IDs:\n");
1022 pos
= Message
.find("NO_PUBKEY ");
1023 if (pos
!= std::string::npos
)
1025 string::size_type start
= pos
+strlen("NO_PUBKEY ");
1026 string Fingerprint
= Message
.substr(start
, Message
.find("\n")-start
);
1027 missingkeys
+= (Fingerprint
);
1029 if(!missingkeys
.empty())
1030 _error
->Warning("%s", (msg
+ missingkeys
).c_str());
1032 string Transformed
= TransactionManager
->MetaIndexParser
->GetExpectedDist();
1034 if (Transformed
== "../project/experimental")
1036 Transformed
= "experimental";
1039 pos
= Transformed
.rfind('/');
1040 if (pos
!= string::npos
)
1042 Transformed
= Transformed
.substr(0, pos
);
1045 if (Transformed
== ".")
1050 if (_config
->FindB("Acquire::Check-Valid-Until", true) == true &&
1051 TransactionManager
->MetaIndexParser
->GetValidUntil() > 0) {
1052 time_t const invalid_since
= time(NULL
) - TransactionManager
->MetaIndexParser
->GetValidUntil();
1053 if (invalid_since
> 0)
1057 // TRANSLATOR: The first %s is the URL of the bad Release file, the second is
1058 // the time since then the file is invalid - formated in the same way as in
1059 // the download progress display (e.g. 7d 3h 42min 1s)
1060 _("Release file for %s is expired (invalid since %s). "
1061 "Updates for this repository will not be applied."),
1062 Target
.URI
.c_str(), TimeToStr(invalid_since
).c_str());
1063 if (ErrorText
.empty())
1065 return _error
->Error("%s", errmsg
.c_str());
1069 /* Did we get a file older than what we have? This is a last minute IMS hit and doubles
1070 as a prevention of downgrading us to older (still valid) files */
1071 if (TransactionManager
->IMSHit
== false && TransactionManager
->LastMetaIndexParser
!= NULL
&&
1072 TransactionManager
->LastMetaIndexParser
->GetDate() > TransactionManager
->MetaIndexParser
->GetDate())
1074 TransactionManager
->IMSHit
= true;
1075 unlink(DestFile
.c_str());
1076 PartialFile
= DestFile
= GetFinalFilename();
1077 delete TransactionManager
->MetaIndexParser
;
1078 TransactionManager
->MetaIndexParser
= TransactionManager
->LastMetaIndexParser
;
1079 TransactionManager
->LastMetaIndexParser
= NULL
;
1082 if (_config
->FindB("Debug::pkgAcquire::Auth", false))
1084 std::cerr
<< "Got Codename: " << TransactionManager
->MetaIndexParser
->GetDist() << std::endl
;
1085 std::cerr
<< "Expecting Dist: " << TransactionManager
->MetaIndexParser
->GetExpectedDist() << std::endl
;
1086 std::cerr
<< "Transformed Dist: " << Transformed
<< std::endl
;
1089 if (TransactionManager
->MetaIndexParser
->CheckDist(Transformed
) == false)
1091 // This might become fatal one day
1092 // Status = StatAuthError;
1093 // ErrorText = "Conflicting distribution; expected "
1094 // + MetaIndexParser->GetExpectedDist() + " but got "
1095 // + MetaIndexParser->GetDist();
1097 if (!Transformed
.empty())
1099 _error
->Warning(_("Conflicting distribution: %s (expected %s but got %s)"),
1100 Desc
.Description
.c_str(),
1101 Transformed
.c_str(),
1102 TransactionManager
->MetaIndexParser
->GetDist().c_str());
1110 pkgAcqMetaClearSig::pkgAcqMetaClearSig(pkgAcquire
* const Owner
, /*{{{*/
1111 IndexTarget
const &ClearsignedTarget
,
1112 IndexTarget
const &DetachedDataTarget
, IndexTarget
const &DetachedSigTarget
,
1113 std::vector
<IndexTarget
> const IndexTargets
,
1114 indexRecords
* const MetaIndexParser
) :
1115 pkgAcqMetaIndex(Owner
, this, ClearsignedTarget
, DetachedSigTarget
, IndexTargets
, MetaIndexParser
),
1116 ClearsignedTarget(ClearsignedTarget
),
1117 DetachedDataTarget(DetachedDataTarget
), DetachedSigTarget(DetachedSigTarget
)
1119 // index targets + (worst case:) Release/Release.gpg
1120 ExpectedAdditionalItems
= IndexTargets
.size() + 2;
1121 TransactionManager
->Add(this);
1124 pkgAcqMetaClearSig::~pkgAcqMetaClearSig() /*{{{*/
1128 // pkgAcqMetaClearSig::Custom600Headers - Insert custom request headers /*{{{*/
1129 string
pkgAcqMetaClearSig::Custom600Headers() const
1131 string Header
= pkgAcqMetaBase::Custom600Headers();
1132 Header
+= "\nFail-Ignore: true";
1136 // pkgAcqMetaClearSig::Done - We got a file /*{{{*/
1137 void pkgAcqMetaClearSig::Done(std::string
const &Message
,
1138 HashStringList
const &Hashes
,
1139 pkgAcquire::MethodConfig
const * const Cnf
)
1141 Item::Done(Message
, Hashes
, Cnf
);
1143 // if we expect a ClearTextSignature (InRelease), ensure that
1144 // this is what we get and if not fail to queue a
1145 // Release/Release.gpg, see #346386
1146 if (FileExists(DestFile
) && !StartsWithGPGClearTextSignature(DestFile
))
1148 pkgAcquire::Item::Failed(Message
, Cnf
);
1149 RenameOnError(NotClearsigned
);
1150 TransactionManager
->AbortTransaction();
1154 if(AuthPass
== false)
1156 if(CheckDownloadDone(this, Message
, Hashes
) == true)
1157 QueueForSignatureVerify(this, DestFile
, DestFile
);
1160 else if(CheckAuthDone(Message
) == true)
1162 if (TransactionManager
->IMSHit
== false)
1163 TransactionManager
->TransactionStageCopy(this, DestFile
, GetFinalFilename());
1164 else if (RealFileExists(GetFinalFilename()) == false)
1166 // We got an InRelease file IMSHit, but we haven't one, which means
1167 // we had a valid Release/Release.gpg combo stepping in, which we have
1168 // to 'acquire' now to ensure list cleanup isn't removing them
1169 new NoActionItem(Owner
, DetachedDataTarget
);
1170 new NoActionItem(Owner
, DetachedSigTarget
);
1175 void pkgAcqMetaClearSig::Failed(string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
) /*{{{*/
1177 Item::Failed(Message
, Cnf
);
1179 // we failed, we will not get additional items from this method
1180 ExpectedAdditionalItems
= 0;
1182 if (AuthPass
== false)
1184 // Queue the 'old' InRelease file for removal if we try Release.gpg
1185 // as otherwise the file will stay around and gives a false-auth
1186 // impression (CVE-2012-0214)
1187 TransactionManager
->TransactionStageRemoval(this, GetFinalFilename());
1190 new pkgAcqMetaIndex(Owner
, TransactionManager
, DetachedDataTarget
, DetachedSigTarget
, IndexTargets
, TransactionManager
->MetaIndexParser
);
1194 if(CheckStopAuthentication(this, Message
))
1197 _error
->Warning(_("The data from '%s' is not signed. Packages "
1198 "from that repository can not be authenticated."),
1199 ClearsignedTarget
.Description
.c_str());
1201 // No Release file was present, or verification failed, so fall
1202 // back to queueing Packages files without verification
1203 // only allow going further if the users explicitely wants it
1204 if(AllowInsecureRepositories(TransactionManager
->MetaIndexParser
, TransactionManager
, this) == true)
1208 /* InRelease files become Release files, otherwise
1209 * they would be considered as trusted later on */
1210 string
const FinalRelease
= GetFinalFileNameFromURI(DetachedDataTarget
.URI
);
1211 string
const PartialRelease
= GetPartialFileNameFromURI(DetachedDataTarget
.URI
);
1212 string
const FinalReleasegpg
= GetFinalFileNameFromURI(DetachedSigTarget
.URI
);
1213 string
const FinalInRelease
= GetFinalFilename();
1214 Rename(DestFile
, PartialRelease
);
1215 TransactionManager
->TransactionStageCopy(this, PartialRelease
, FinalRelease
);
1217 if (RealFileExists(FinalReleasegpg
) || RealFileExists(FinalInRelease
))
1219 // open the last Release if we have it
1220 if (TransactionManager
->IMSHit
== false)
1222 TransactionManager
->LastMetaIndexParser
= new indexRecords
;
1223 _error
->PushToStack();
1224 if (RealFileExists(FinalInRelease
))
1225 TransactionManager
->LastMetaIndexParser
->Load(FinalInRelease
);
1227 TransactionManager
->LastMetaIndexParser
->Load(FinalRelease
);
1228 // its unlikely to happen, but if what we have is bad ignore it
1229 if (_error
->PendingError())
1231 delete TransactionManager
->LastMetaIndexParser
;
1232 TransactionManager
->LastMetaIndexParser
= NULL
;
1234 _error
->RevertToStack();
1238 // we parse the indexes here because at this point the user wanted
1239 // a repository that may potentially harm him
1240 if (TransactionManager
->MetaIndexParser
->Load(PartialRelease
) == false || VerifyVendor(Message
) == false)
1241 /* expired Release files are still a problem you need extra force for */;
1249 pkgAcqMetaIndex::pkgAcqMetaIndex(pkgAcquire
* const Owner
, /*{{{*/
1250 pkgAcqMetaBase
* const TransactionManager
,
1251 IndexTarget
const &DataTarget
,
1252 IndexTarget
const &DetachedSigTarget
,
1253 vector
<IndexTarget
> const IndexTargets
,
1254 indexRecords
* const MetaIndexParser
) :
1255 pkgAcqMetaBase(Owner
, TransactionManager
, IndexTargets
, DataTarget
, MetaIndexParser
),
1256 DetachedSigTarget(DetachedSigTarget
)
1258 if(_config
->FindB("Debug::Acquire::Transaction", false) == true)
1259 std::clog
<< "New pkgAcqMetaIndex with TransactionManager "
1260 << this->TransactionManager
<< std::endl
;
1262 DestFile
= GetPartialFileNameFromURI(DataTarget
.URI
);
1265 Desc
.Description
= DataTarget
.Description
;
1267 Desc
.ShortDesc
= DataTarget
.ShortDesc
;
1268 Desc
.URI
= DataTarget
.URI
;
1270 // we expect more item
1271 ExpectedAdditionalItems
= IndexTargets
.size();
1275 void pkgAcqMetaIndex::Done(string
const &Message
, /*{{{*/
1276 HashStringList
const &Hashes
,
1277 pkgAcquire::MethodConfig
const * const Cfg
)
1279 Item::Done(Message
,Hashes
,Cfg
);
1281 if(CheckDownloadDone(this, Message
, Hashes
))
1283 // we have a Release file, now download the Signature, all further
1284 // verify/queue for additional downloads will be done in the
1285 // pkgAcqMetaSig::Done() code
1286 new pkgAcqMetaSig(Owner
, TransactionManager
, DetachedSigTarget
, this);
1290 // pkgAcqMetaIndex::Failed - no Release file present /*{{{*/
1291 void pkgAcqMetaIndex::Failed(string
const &Message
,
1292 pkgAcquire::MethodConfig
const * const Cnf
)
1294 pkgAcquire::Item::Failed(Message
, Cnf
);
1297 _error
->Warning(_("The repository '%s' does not have a Release file. "
1298 "This is deprecated, please contact the owner of the "
1299 "repository."), Target
.Description
.c_str());
1301 // No Release file was present so fall
1302 // back to queueing Packages files without verification
1303 // only allow going further if the users explicitely wants it
1304 if(AllowInsecureRepositories(TransactionManager
->MetaIndexParser
, TransactionManager
, this) == true)
1306 // ensure old Release files are removed
1307 TransactionManager
->TransactionStageRemoval(this, GetFinalFilename());
1308 delete TransactionManager
->MetaIndexParser
;
1309 TransactionManager
->MetaIndexParser
= NULL
;
1311 // queue without any kind of hashsum support
1312 QueueIndexes(false);
1316 void pkgAcqMetaIndex::Finished() /*{{{*/
1318 if(_config
->FindB("Debug::Acquire::Transaction", false) == true)
1319 std::clog
<< "Finished: " << DestFile
<<std::endl
;
1320 if(TransactionManager
!= NULL
&&
1321 TransactionManager
->TransactionHasError() == false)
1322 TransactionManager
->CommitTransaction();
1325 std::string
pkgAcqMetaIndex::DescURI() const /*{{{*/
1331 // AcqMetaSig::AcqMetaSig - Constructor /*{{{*/
1332 pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire
* const Owner
,
1333 pkgAcqMetaBase
* const TransactionManager
,
1334 IndexTarget
const Target
,
1335 pkgAcqMetaIndex
* const MetaIndex
) :
1336 pkgAcqTransactionItem(Owner
, TransactionManager
, Target
), MetaIndex(MetaIndex
)
1338 DestFile
= GetPartialFileNameFromURI(Target
.URI
);
1340 // remove any partial downloaded sig-file in partial/.
1341 // it may confuse proxies and is too small to warrant a
1342 // partial download anyway
1343 unlink(DestFile
.c_str());
1345 // set the TransactionManager
1346 if(_config
->FindB("Debug::Acquire::Transaction", false) == true)
1347 std::clog
<< "New pkgAcqMetaSig with TransactionManager "
1348 << TransactionManager
<< std::endl
;
1351 Desc
.Description
= Target
.Description
;
1353 Desc
.ShortDesc
= Target
.ShortDesc
;
1354 Desc
.URI
= Target
.URI
;
1356 // If we got a hit for Release, we will get one for Release.gpg too (or obscure errors),
1357 // so we skip the download step and go instantly to verification
1358 if (TransactionManager
->IMSHit
== true && RealFileExists(GetFinalFilename()))
1362 PartialFile
= DestFile
= GetFinalFilename();
1363 MetaIndexFileSignature
= DestFile
;
1364 MetaIndex
->QueueForSignatureVerify(this, MetaIndex
->DestFile
, DestFile
);
1370 pkgAcqMetaSig::~pkgAcqMetaSig() /*{{{*/
1374 // AcqMetaSig::Done - The signature was downloaded/verified /*{{{*/
1375 void pkgAcqMetaSig::Done(string
const &Message
, HashStringList
const &Hashes
,
1376 pkgAcquire::MethodConfig
const * const Cfg
)
1378 if (MetaIndexFileSignature
.empty() == false)
1380 DestFile
= MetaIndexFileSignature
;
1381 MetaIndexFileSignature
.clear();
1383 Item::Done(Message
, Hashes
, Cfg
);
1385 if(MetaIndex
->AuthPass
== false)
1387 if(MetaIndex
->CheckDownloadDone(this, Message
, Hashes
) == true)
1389 // destfile will be modified to point to MetaIndexFile for the
1390 // gpgv method, so we need to save it here
1391 MetaIndexFileSignature
= DestFile
;
1392 MetaIndex
->QueueForSignatureVerify(this, MetaIndex
->DestFile
, DestFile
);
1396 else if(MetaIndex
->CheckAuthDone(Message
) == true)
1398 if (TransactionManager
->IMSHit
== false)
1400 TransactionManager
->TransactionStageCopy(this, DestFile
, GetFinalFilename());
1401 TransactionManager
->TransactionStageCopy(MetaIndex
, MetaIndex
->DestFile
, MetaIndex
->GetFinalFilename());
1406 void pkgAcqMetaSig::Failed(string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
)/*{{{*/
1408 Item::Failed(Message
,Cnf
);
1410 // check if we need to fail at this point
1411 if (MetaIndex
->AuthPass
== true && MetaIndex
->CheckStopAuthentication(this, Message
))
1414 string
const FinalRelease
= MetaIndex
->GetFinalFilename();
1415 string
const FinalReleasegpg
= GetFinalFilename();
1416 string
const FinalInRelease
= TransactionManager
->GetFinalFilename();
1418 if (RealFileExists(FinalReleasegpg
) || RealFileExists(FinalInRelease
))
1420 std::string downgrade_msg
;
1421 strprintf(downgrade_msg
, _("The repository '%s' is no longer signed."),
1422 MetaIndex
->Target
.Description
.c_str());
1423 if(_config
->FindB("Acquire::AllowDowngradeToInsecureRepositories"))
1425 // meh, the users wants to take risks (we still mark the packages
1426 // from this repository as unauthenticated)
1427 _error
->Warning("%s", downgrade_msg
.c_str());
1428 _error
->Warning(_("This is normally not allowed, but the option "
1429 "Acquire::AllowDowngradeToInsecureRepositories was "
1430 "given to override it."));
1433 _error
->Error("%s", downgrade_msg
.c_str());
1434 if (TransactionManager
->IMSHit
== false)
1435 Rename(MetaIndex
->DestFile
, MetaIndex
->DestFile
+ ".FAILED");
1436 Item::Failed("Message: " + downgrade_msg
, Cnf
);
1437 TransactionManager
->AbortTransaction();
1442 _error
->Warning(_("The data from '%s' is not signed. Packages "
1443 "from that repository can not be authenticated."),
1444 MetaIndex
->Target
.Description
.c_str());
1446 // ensures that a Release.gpg file in the lists/ is removed by the transaction
1447 TransactionManager
->TransactionStageRemoval(this, DestFile
);
1449 // only allow going further if the users explicitely wants it
1450 if(AllowInsecureRepositories(TransactionManager
->MetaIndexParser
, TransactionManager
, this) == true)
1452 if (RealFileExists(FinalReleasegpg
) || RealFileExists(FinalInRelease
))
1454 // open the last Release if we have it
1455 if (TransactionManager
->IMSHit
== false)
1457 TransactionManager
->LastMetaIndexParser
= new indexRecords
;
1458 _error
->PushToStack();
1459 if (RealFileExists(FinalInRelease
))
1460 TransactionManager
->LastMetaIndexParser
->Load(FinalInRelease
);
1462 TransactionManager
->LastMetaIndexParser
->Load(FinalRelease
);
1463 // its unlikely to happen, but if what we have is bad ignore it
1464 if (_error
->PendingError())
1466 delete TransactionManager
->LastMetaIndexParser
;
1467 TransactionManager
->LastMetaIndexParser
= NULL
;
1469 _error
->RevertToStack();
1473 // we parse the indexes here because at this point the user wanted
1474 // a repository that may potentially harm him
1475 if (TransactionManager
->MetaIndexParser
->Load(MetaIndex
->DestFile
) == false || MetaIndex
->VerifyVendor(Message
) == false)
1476 /* expired Release files are still a problem you need extra force for */;
1478 MetaIndex
->QueueIndexes(true);
1480 TransactionManager
->TransactionStageCopy(MetaIndex
, MetaIndex
->DestFile
, MetaIndex
->GetFinalFilename());
1483 // FIXME: this is used often (e.g. in pkgAcqIndexTrans) so refactor
1484 if (Cnf
->LocalOnly
== true ||
1485 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == false)
1494 // AcqBaseIndex - Constructor /*{{{*/
1495 pkgAcqBaseIndex::pkgAcqBaseIndex(pkgAcquire
* const Owner
,
1496 pkgAcqMetaBase
* const TransactionManager
,
1497 IndexTarget
const Target
)
1498 : pkgAcqTransactionItem(Owner
, TransactionManager
, Target
)
1503 // AcqDiffIndex::AcqDiffIndex - Constructor /*{{{*/
1504 // ---------------------------------------------------------------------
1505 /* Get the DiffIndex file first and see if there are patches available
1506 * If so, create a pkgAcqIndexDiffs fetcher that will get and apply the
1507 * patches. If anything goes wrong in that process, it will fall back to
1508 * the original packages file
1510 pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire
* const Owner
,
1511 pkgAcqMetaBase
* const TransactionManager
,
1512 IndexTarget
const Target
)
1513 : pkgAcqBaseIndex(Owner
, TransactionManager
, Target
)
1515 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
1518 Desc
.Description
= Target
.Description
+ ".diff/Index";
1519 Desc
.ShortDesc
= Target
.ShortDesc
;
1520 Desc
.URI
= Target
.URI
+ ".diff/Index";
1522 DestFile
= GetPartialFileNameFromURI(Desc
.URI
);
1525 std::clog
<< "pkgAcqDiffIndex: " << Desc
.URI
<< std::endl
;
1530 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
1531 // ---------------------------------------------------------------------
1532 /* The only header we use is the last-modified header. */
1533 string
pkgAcqDiffIndex::Custom600Headers() const
1535 string
const Final
= GetFinalFilename();
1538 std::clog
<< "Custom600Header-IMS: " << Final
<< std::endl
;
1541 if (stat(Final
.c_str(),&Buf
) != 0)
1542 return "\nIndex-File: true";
1544 return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
1547 void pkgAcqDiffIndex::QueueOnIMSHit() const /*{{{*/
1549 // list cleanup needs to know that this file as well as the already
1550 // present index is ours, so we create an empty diff to save it for us
1551 new pkgAcqIndexDiffs(Owner
, TransactionManager
, Target
);
1554 bool pkgAcqDiffIndex::ParseDiffIndex(string
const &IndexDiffFile
) /*{{{*/
1556 // failing here is fine: our caller will take care of trying to
1557 // get the complete file if patching fails
1559 std::clog
<< "pkgAcqDiffIndex::ParseIndexDiff() " << IndexDiffFile
1562 FileFd
Fd(IndexDiffFile
,FileFd::ReadOnly
);
1564 if (_error
->PendingError() == true)
1568 if(unlikely(TF
.Step(Tags
) == false))
1571 HashStringList ServerHashes
;
1572 unsigned long long ServerSize
= 0;
1574 for (char const * const * type
= HashString::SupportedHashes(); *type
!= NULL
; ++type
)
1576 std::string tagname
= *type
;
1577 tagname
.append("-Current");
1578 std::string
const tmp
= Tags
.FindS(tagname
.c_str());
1579 if (tmp
.empty() == true)
1583 unsigned long long size
;
1584 std::stringstream
ss(tmp
);
1586 if (unlikely(hash
.empty() == true))
1588 if (unlikely(ServerSize
!= 0 && ServerSize
!= size
))
1590 ServerHashes
.push_back(HashString(*type
, hash
));
1594 if (ServerHashes
.usable() == false)
1597 std::clog
<< "pkgAcqDiffIndex: " << IndexDiffFile
<< ": Did not find a good hashsum in the index" << std::endl
;
1601 std::string
const CurrentPackagesFile
= GetFinalFileNameFromURI(Target
.URI
);
1602 HashStringList
const TargetFileHashes
= GetExpectedHashesFor(Target
.MetaKey
);
1603 if (TargetFileHashes
.usable() == false || ServerHashes
!= TargetFileHashes
)
1607 std::clog
<< "pkgAcqDiffIndex: " << IndexDiffFile
<< ": Index has different hashes than parser, probably older, so fail pdiffing" << std::endl
;
1608 printHashSumComparision(CurrentPackagesFile
, ServerHashes
, TargetFileHashes
);
1613 HashStringList LocalHashes
;
1614 // try avoiding calculating the hash here as this is costly
1615 if (TransactionManager
->LastMetaIndexParser
!= NULL
)
1616 LocalHashes
= GetExpectedHashesFromFor(TransactionManager
->LastMetaIndexParser
, Target
.MetaKey
);
1617 if (LocalHashes
.usable() == false)
1619 FileFd
fd(CurrentPackagesFile
, FileFd::ReadOnly
);
1620 Hashes
LocalHashesCalc(ServerHashes
);
1621 LocalHashesCalc
.AddFD(fd
);
1622 LocalHashes
= LocalHashesCalc
.GetHashStringList();
1625 if (ServerHashes
== LocalHashes
)
1627 // we have the same sha1 as the server so we are done here
1629 std::clog
<< "pkgAcqDiffIndex: Package file " << CurrentPackagesFile
<< " is up-to-date" << std::endl
;
1635 std::clog
<< "Server-Current: " << ServerHashes
.find(NULL
)->toStr() << " and we start at "
1636 << CurrentPackagesFile
<< " " << LocalHashes
.FileSize() << " " << LocalHashes
.find(NULL
)->toStr() << std::endl
;
1638 // parse all of (provided) history
1639 vector
<DiffInfo
> available_patches
;
1640 bool firstAcceptedHashes
= true;
1641 for (char const * const * type
= HashString::SupportedHashes(); *type
!= NULL
; ++type
)
1643 if (LocalHashes
.find(*type
) == NULL
)
1646 std::string tagname
= *type
;
1647 tagname
.append("-History");
1648 std::string
const tmp
= Tags
.FindS(tagname
.c_str());
1649 if (tmp
.empty() == true)
1652 string hash
, filename
;
1653 unsigned long long size
;
1654 std::stringstream
ss(tmp
);
1656 while (ss
>> hash
>> size
>> filename
)
1658 if (unlikely(hash
.empty() == true || filename
.empty() == true))
1661 // see if we have a record for this file already
1662 std::vector
<DiffInfo
>::iterator cur
= available_patches
.begin();
1663 for (; cur
!= available_patches
.end(); ++cur
)
1665 if (cur
->file
!= filename
)
1667 cur
->result_hashes
.push_back(HashString(*type
, hash
));
1670 if (cur
!= available_patches
.end())
1672 if (firstAcceptedHashes
== true)
1675 next
.file
= filename
;
1676 next
.result_hashes
.push_back(HashString(*type
, hash
));
1677 next
.result_hashes
.FileSize(size
);
1678 available_patches
.push_back(next
);
1683 std::clog
<< "pkgAcqDiffIndex: " << IndexDiffFile
<< ": File " << filename
1684 << " wasn't in the list for the first parsed hash! (history)" << std::endl
;
1688 firstAcceptedHashes
= false;
1691 if (unlikely(available_patches
.empty() == true))
1694 std::clog
<< "pkgAcqDiffIndex: " << IndexDiffFile
<< ": "
1695 << "Couldn't find any patches for the patch series." << std::endl
;
1699 for (char const * const * type
= HashString::SupportedHashes(); *type
!= NULL
; ++type
)
1701 if (LocalHashes
.find(*type
) == NULL
)
1704 std::string tagname
= *type
;
1705 tagname
.append("-Patches");
1706 std::string
const tmp
= Tags
.FindS(tagname
.c_str());
1707 if (tmp
.empty() == true)
1710 string hash
, filename
;
1711 unsigned long long size
;
1712 std::stringstream
ss(tmp
);
1714 while (ss
>> hash
>> size
>> filename
)
1716 if (unlikely(hash
.empty() == true || filename
.empty() == true))
1719 // see if we have a record for this file already
1720 std::vector
<DiffInfo
>::iterator cur
= available_patches
.begin();
1721 for (; cur
!= available_patches
.end(); ++cur
)
1723 if (cur
->file
!= filename
)
1725 if (cur
->patch_hashes
.empty())
1726 cur
->patch_hashes
.FileSize(size
);
1727 cur
->patch_hashes
.push_back(HashString(*type
, hash
));
1730 if (cur
!= available_patches
.end())
1733 std::clog
<< "pkgAcqDiffIndex: " << IndexDiffFile
<< ": File " << filename
1734 << " wasn't in the list for the first parsed hash! (patches)" << std::endl
;
1739 for (char const * const * type
= HashString::SupportedHashes(); *type
!= NULL
; ++type
)
1741 std::string tagname
= *type
;
1742 tagname
.append("-Download");
1743 std::string
const tmp
= Tags
.FindS(tagname
.c_str());
1744 if (tmp
.empty() == true)
1747 string hash
, filename
;
1748 unsigned long long size
;
1749 std::stringstream
ss(tmp
);
1751 // FIXME: all of pdiff supports only .gz compressed patches
1752 while (ss
>> hash
>> size
>> filename
)
1754 if (unlikely(hash
.empty() == true || filename
.empty() == true))
1756 if (unlikely(APT::String::Endswith(filename
, ".gz") == false))
1758 filename
.erase(filename
.length() - 3);
1760 // see if we have a record for this file already
1761 std::vector
<DiffInfo
>::iterator cur
= available_patches
.begin();
1762 for (; cur
!= available_patches
.end(); ++cur
)
1764 if (cur
->file
!= filename
)
1766 if (cur
->download_hashes
.empty())
1767 cur
->download_hashes
.FileSize(size
);
1768 cur
->download_hashes
.push_back(HashString(*type
, hash
));
1771 if (cur
!= available_patches
.end())
1774 std::clog
<< "pkgAcqDiffIndex: " << IndexDiffFile
<< ": File " << filename
1775 << " wasn't in the list for the first parsed hash! (download)" << std::endl
;
1781 bool foundStart
= false;
1782 for (std::vector
<DiffInfo
>::iterator cur
= available_patches
.begin();
1783 cur
!= available_patches
.end(); ++cur
)
1785 if (LocalHashes
!= cur
->result_hashes
)
1788 available_patches
.erase(available_patches
.begin(), cur
);
1793 if (foundStart
== false || unlikely(available_patches
.empty() == true))
1796 std::clog
<< "pkgAcqDiffIndex: " << IndexDiffFile
<< ": "
1797 << "Couldn't find the start of the patch series." << std::endl
;
1801 // patching with too many files is rather slow compared to a fast download
1802 unsigned long const fileLimit
= _config
->FindI("Acquire::PDiffs::FileLimit", 0);
1803 if (fileLimit
!= 0 && fileLimit
< available_patches
.size())
1806 std::clog
<< "Need " << available_patches
.size() << " diffs (Limit is " << fileLimit
1807 << ") so fallback to complete download" << std::endl
;
1811 // calculate the size of all patches we have to get
1812 // note that all sizes are uncompressed, while we download compressed files
1813 unsigned long long patchesSize
= 0;
1814 for (std::vector
<DiffInfo
>::const_iterator cur
= available_patches
.begin();
1815 cur
!= available_patches
.end(); ++cur
)
1816 patchesSize
+= cur
->patch_hashes
.FileSize();
1817 unsigned long long const sizeLimit
= ServerSize
* _config
->FindI("Acquire::PDiffs::SizeLimit", 100);
1818 if (sizeLimit
> 0 && (sizeLimit
/100) < patchesSize
)
1821 std::clog
<< "Need " << patchesSize
<< " bytes (Limit is " << sizeLimit
/100
1822 << ") so fallback to complete download" << std::endl
;
1826 // we have something, queue the diffs
1827 string::size_type
const last_space
= Description
.rfind(" ");
1828 if(last_space
!= string::npos
)
1829 Description
.erase(last_space
, Description
.size()-last_space
);
1831 /* decide if we should download patches one by one or in one go:
1832 The first is good if the server merges patches, but many don't so client
1833 based merging can be attempt in which case the second is better.
1834 "bad things" will happen if patches are merged on the server,
1835 but client side merging is attempt as well */
1836 bool pdiff_merge
= _config
->FindB("Acquire::PDiffs::Merge", true);
1837 if (pdiff_merge
== true)
1839 // reprepro adds this flag if it has merged patches on the server
1840 std::string
const precedence
= Tags
.FindS("X-Patch-Precedence");
1841 pdiff_merge
= (precedence
!= "merged");
1844 if (pdiff_merge
== false)
1845 new pkgAcqIndexDiffs(Owner
, TransactionManager
, Target
, available_patches
);
1848 std::vector
<pkgAcqIndexMergeDiffs
*> *diffs
= new std::vector
<pkgAcqIndexMergeDiffs
*>(available_patches
.size());
1849 for(size_t i
= 0; i
< available_patches
.size(); ++i
)
1850 (*diffs
)[i
] = new pkgAcqIndexMergeDiffs(Owner
, TransactionManager
,
1852 available_patches
[i
],
1862 void pkgAcqDiffIndex::Failed(string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
)/*{{{*/
1864 Item::Failed(Message
,Cnf
);
1868 std::clog
<< "pkgAcqDiffIndex failed: " << Desc
.URI
<< " with " << Message
<< std::endl
1869 << "Falling back to normal index file acquire" << std::endl
;
1871 new pkgAcqIndex(Owner
, TransactionManager
, Target
);
1874 void pkgAcqDiffIndex::Done(string
const &Message
,HashStringList
const &Hashes
, /*{{{*/
1875 pkgAcquire::MethodConfig
const * const Cnf
)
1878 std::clog
<< "pkgAcqDiffIndex::Done(): " << Desc
.URI
<< std::endl
;
1880 Item::Done(Message
, Hashes
, Cnf
);
1882 string
const FinalFile
= GetFinalFilename();
1883 if(StringToBool(LookupTag(Message
,"IMS-Hit"),false))
1884 DestFile
= FinalFile
;
1886 if(ParseDiffIndex(DestFile
) == false)
1888 Failed("Message: Couldn't parse pdiff index", Cnf
);
1889 // queue for final move - this should happen even if we fail
1890 // while parsing (e.g. on sizelimit) and download the complete file.
1891 TransactionManager
->TransactionStageCopy(this, DestFile
, FinalFile
);
1895 TransactionManager
->TransactionStageCopy(this, DestFile
, FinalFile
);
1905 // AcqIndexDiffs::AcqIndexDiffs - Constructor /*{{{*/
1906 // ---------------------------------------------------------------------
1907 /* The package diff is added to the queue. one object is constructed
1908 * for each diff and the index
1910 pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire
* const Owner
,
1911 pkgAcqMetaBase
* const TransactionManager
,
1912 IndexTarget
const Target
,
1913 vector
<DiffInfo
> const &diffs
)
1914 : pkgAcqBaseIndex(Owner
, TransactionManager
, Target
),
1915 available_patches(diffs
)
1917 DestFile
= GetPartialFileNameFromURI(Target
.URI
);
1919 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
1922 Description
= Target
.Description
;
1923 Desc
.ShortDesc
= Target
.ShortDesc
;
1925 if(available_patches
.empty() == true)
1927 // we are done (yeah!), check hashes against the final file
1928 DestFile
= GetFinalFileNameFromURI(Target
.URI
);
1933 // patching needs to be bootstrapped with the 'old' version
1934 std::string
const PartialFile
= GetPartialFileNameFromURI(Target
.URI
);
1935 if (RealFileExists(PartialFile
) == false)
1937 if (symlink(GetFinalFilename().c_str(), PartialFile
.c_str()) != 0)
1939 Failed("Link creation of " + PartialFile
+ " to " + GetFinalFilename() + " failed", NULL
);
1944 // get the next diff
1945 State
= StateFetchDiff
;
1950 void pkgAcqIndexDiffs::Failed(string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
)/*{{{*/
1952 Item::Failed(Message
,Cnf
);
1956 std::clog
<< "pkgAcqIndexDiffs failed: " << Desc
.URI
<< " with " << Message
<< std::endl
1957 << "Falling back to normal index file acquire" << std::endl
;
1958 DestFile
= GetPartialFileNameFromURI(Target
.URI
);
1959 RenameOnError(PDiffError
);
1960 std::string
const patchname
= GetDiffsPatchFileName(DestFile
);
1961 if (RealFileExists(patchname
))
1962 rename(patchname
.c_str(), std::string(patchname
+ ".FAILED").c_str());
1963 new pkgAcqIndex(Owner
, TransactionManager
, Target
);
1967 // Finish - helper that cleans the item out of the fetcher queue /*{{{*/
1968 void pkgAcqIndexDiffs::Finish(bool allDone
)
1971 std::clog
<< "pkgAcqIndexDiffs::Finish(): "
1973 << Desc
.URI
<< std::endl
;
1975 // we restore the original name, this is required, otherwise
1976 // the file will be cleaned
1979 TransactionManager
->TransactionStageCopy(this, DestFile
, GetFinalFilename());
1981 // this is for the "real" finish
1986 std::clog
<< "\n\nallDone: " << DestFile
<< "\n" << std::endl
;
1991 std::clog
<< "Finishing: " << Desc
.URI
<< std::endl
;
1998 bool pkgAcqIndexDiffs::QueueNextDiff() /*{{{*/
2000 // calc sha1 of the just patched file
2001 std::string
const FinalFile
= GetPartialFileNameFromURI(Target
.URI
);
2003 if(!FileExists(FinalFile
))
2005 Failed("Message: No FinalFile " + FinalFile
+ " available", NULL
);
2009 FileFd
fd(FinalFile
, FileFd::ReadOnly
);
2010 Hashes LocalHashesCalc
;
2011 LocalHashesCalc
.AddFD(fd
);
2012 HashStringList
const LocalHashes
= LocalHashesCalc
.GetHashStringList();
2015 std::clog
<< "QueueNextDiff: " << FinalFile
<< " (" << LocalHashes
.find(NULL
)->toStr() << ")" << std::endl
;
2017 HashStringList
const TargetFileHashes
= GetExpectedHashesFor(Target
.MetaKey
);
2018 if (unlikely(LocalHashes
.usable() == false || TargetFileHashes
.usable() == false))
2020 Failed("Local/Expected hashes are not usable", NULL
);
2025 // final file reached before all patches are applied
2026 if(LocalHashes
== TargetFileHashes
)
2032 // remove all patches until the next matching patch is found
2033 // this requires the Index file to be ordered
2034 for(vector
<DiffInfo
>::iterator I
= available_patches
.begin();
2035 available_patches
.empty() == false &&
2036 I
!= available_patches
.end() &&
2037 I
->result_hashes
!= LocalHashes
;
2040 available_patches
.erase(I
);
2043 // error checking and falling back if no patch was found
2044 if(available_patches
.empty() == true)
2046 Failed("No patches left to reach target", NULL
);
2050 // queue the right diff
2051 Desc
.URI
= Target
.URI
+ ".diff/" + available_patches
[0].file
+ ".gz";
2052 Desc
.Description
= Description
+ " " + available_patches
[0].file
+ string(".pdiff");
2053 DestFile
= GetPartialFileNameFromURI(Target
.URI
+ ".diff/" + available_patches
[0].file
);
2056 std::clog
<< "pkgAcqIndexDiffs::QueueNextDiff(): " << Desc
.URI
<< std::endl
;
2063 void pkgAcqIndexDiffs::Done(string
const &Message
, HashStringList
const &Hashes
, /*{{{*/
2064 pkgAcquire::MethodConfig
const * const Cnf
)
2067 std::clog
<< "pkgAcqIndexDiffs::Done(): " << Desc
.URI
<< std::endl
;
2069 Item::Done(Message
, Hashes
, Cnf
);
2071 std::string
const FinalFile
= GetPartialFileNameFromURI(Target
.URI
);
2072 std::string
const PatchFile
= GetDiffsPatchFileName(FinalFile
);
2074 // success in downloading a diff, enter ApplyDiff state
2075 if(State
== StateFetchDiff
)
2077 Rename(DestFile
, PatchFile
);
2080 std::clog
<< "Sending to rred method: " << FinalFile
<< std::endl
;
2082 State
= StateApplyDiff
;
2084 Desc
.URI
= "rred:" + FinalFile
;
2086 SetActiveSubprocess("rred");
2090 // success in download/apply a diff, queue next (if needed)
2091 if(State
== StateApplyDiff
)
2093 // remove the just applied patch
2094 available_patches
.erase(available_patches
.begin());
2095 unlink(PatchFile
.c_str());
2100 std::clog
<< "Moving patched file in place: " << std::endl
2101 << DestFile
<< " -> " << FinalFile
<< std::endl
;
2103 Rename(DestFile
,FinalFile
);
2104 chmod(FinalFile
.c_str(),0644);
2106 // see if there is more to download
2107 if(available_patches
.empty() == false) {
2108 new pkgAcqIndexDiffs(Owner
, TransactionManager
, Target
,
2113 DestFile
= FinalFile
;
2114 return Finish(true);
2118 std::string
pkgAcqIndexDiffs::Custom600Headers() const /*{{{*/
2120 if(State
!= StateApplyDiff
)
2121 return pkgAcqBaseIndex::Custom600Headers();
2122 std::ostringstream patchhashes
;
2123 HashStringList
const ExpectedHashes
= available_patches
[0].patch_hashes
;
2124 for (HashStringList::const_iterator hs
= ExpectedHashes
.begin(); hs
!= ExpectedHashes
.end(); ++hs
)
2125 patchhashes
<< "\nPatch-0-" << hs
->HashType() << "-Hash: " << hs
->HashValue();
2126 patchhashes
<< pkgAcqBaseIndex::Custom600Headers();
2127 return patchhashes
.str();
2131 // AcqIndexMergeDiffs::AcqIndexMergeDiffs - Constructor /*{{{*/
2132 pkgAcqIndexMergeDiffs::pkgAcqIndexMergeDiffs(pkgAcquire
* const Owner
,
2133 pkgAcqMetaBase
* const TransactionManager
,
2134 IndexTarget
const Target
,
2135 DiffInfo
const &patch
,
2136 std::vector
<pkgAcqIndexMergeDiffs
*> const * const allPatches
)
2137 : pkgAcqBaseIndex(Owner
, TransactionManager
, Target
),
2138 patch(patch
), allPatches(allPatches
), State(StateFetchDiff
)
2140 Debug
= _config
->FindB("Debug::pkgAcquire::Diffs",false);
2143 Description
= Target
.Description
;
2144 Desc
.ShortDesc
= Target
.ShortDesc
;
2146 Desc
.URI
= Target
.URI
+ ".diff/" + patch
.file
+ ".gz";
2147 Desc
.Description
= Description
+ " " + patch
.file
+ string(".pdiff");
2149 DestFile
= GetPartialFileNameFromURI(Target
.URI
+ ".diff/" + patch
.file
);
2152 std::clog
<< "pkgAcqIndexMergeDiffs: " << Desc
.URI
<< std::endl
;
2157 void pkgAcqIndexMergeDiffs::Failed(string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
)/*{{{*/
2160 std::clog
<< "pkgAcqIndexMergeDiffs failed: " << Desc
.URI
<< " with " << Message
<< std::endl
;
2162 Item::Failed(Message
,Cnf
);
2165 // check if we are the first to fail, otherwise we are done here
2166 State
= StateDoneDiff
;
2167 for (std::vector
<pkgAcqIndexMergeDiffs
*>::const_iterator I
= allPatches
->begin();
2168 I
!= allPatches
->end(); ++I
)
2169 if ((*I
)->State
== StateErrorDiff
)
2172 // first failure means we should fallback
2173 State
= StateErrorDiff
;
2175 std::clog
<< "Falling back to normal index file acquire" << std::endl
;
2176 DestFile
= GetPartialFileNameFromURI(Target
.URI
);
2177 RenameOnError(PDiffError
);
2178 std::string
const patchname
= GetMergeDiffsPatchFileName(DestFile
, patch
.file
);
2179 if (RealFileExists(patchname
))
2180 rename(patchname
.c_str(), std::string(patchname
+ ".FAILED").c_str());
2181 new pkgAcqIndex(Owner
, TransactionManager
, Target
);
2184 void pkgAcqIndexMergeDiffs::Done(string
const &Message
, HashStringList
const &Hashes
, /*{{{*/
2185 pkgAcquire::MethodConfig
const * const Cnf
)
2188 std::clog
<< "pkgAcqIndexMergeDiffs::Done(): " << Desc
.URI
<< std::endl
;
2190 Item::Done(Message
, Hashes
, Cnf
);
2192 string
const FinalFile
= GetPartialFileNameFromURI(Target
.URI
);
2193 if (State
== StateFetchDiff
)
2195 Rename(DestFile
, GetMergeDiffsPatchFileName(FinalFile
, patch
.file
));
2197 // check if this is the last completed diff
2198 State
= StateDoneDiff
;
2199 for (std::vector
<pkgAcqIndexMergeDiffs
*>::const_iterator I
= allPatches
->begin();
2200 I
!= allPatches
->end(); ++I
)
2201 if ((*I
)->State
!= StateDoneDiff
)
2204 std::clog
<< "Not the last done diff in the batch: " << Desc
.URI
<< std::endl
;
2208 // this is the last completed diff, so we are ready to apply now
2209 State
= StateApplyDiff
;
2211 // patching needs to be bootstrapped with the 'old' version
2212 if (symlink(GetFinalFilename().c_str(), FinalFile
.c_str()) != 0)
2214 Failed("Link creation of " + FinalFile
+ " to " + GetFinalFilename() + " failed", NULL
);
2219 std::clog
<< "Sending to rred method: " << FinalFile
<< std::endl
;
2222 Desc
.URI
= "rred:" + FinalFile
;
2224 SetActiveSubprocess("rred");
2227 // success in download/apply all diffs, clean up
2228 else if (State
== StateApplyDiff
)
2230 // move the result into place
2231 std::string
const Final
= GetFinalFilename();
2233 std::clog
<< "Queue patched file in place: " << std::endl
2234 << DestFile
<< " -> " << Final
<< std::endl
;
2236 // queue for copy by the transaction manager
2237 TransactionManager
->TransactionStageCopy(this, DestFile
, Final
);
2239 // ensure the ed's are gone regardless of list-cleanup
2240 for (std::vector
<pkgAcqIndexMergeDiffs
*>::const_iterator I
= allPatches
->begin();
2241 I
!= allPatches
->end(); ++I
)
2243 std::string
const PartialFile
= GetPartialFileNameFromURI(Target
.URI
);
2244 std::string
const patch
= GetMergeDiffsPatchFileName(PartialFile
, (*I
)->patch
.file
);
2245 unlink(patch
.c_str());
2247 unlink(FinalFile
.c_str());
2252 std::clog
<< "allDone: " << DestFile
<< "\n" << std::endl
;
2256 std::string
pkgAcqIndexMergeDiffs::Custom600Headers() const /*{{{*/
2258 if(State
!= StateApplyDiff
)
2259 return pkgAcqBaseIndex::Custom600Headers();
2260 std::ostringstream patchhashes
;
2261 unsigned int seen_patches
= 0;
2262 for (std::vector
<pkgAcqIndexMergeDiffs
*>::const_iterator I
= allPatches
->begin();
2263 I
!= allPatches
->end(); ++I
)
2265 HashStringList
const ExpectedHashes
= (*I
)->patch
.patch_hashes
;
2266 for (HashStringList::const_iterator hs
= ExpectedHashes
.begin(); hs
!= ExpectedHashes
.end(); ++hs
)
2267 patchhashes
<< "\nPatch-" << seen_patches
<< "-" << hs
->HashType() << "-Hash: " << hs
->HashValue();
2270 patchhashes
<< pkgAcqBaseIndex::Custom600Headers();
2271 return patchhashes
.str();
2275 // AcqIndex::AcqIndex - Constructor /*{{{*/
2276 pkgAcqIndex::pkgAcqIndex(pkgAcquire
* const Owner
,
2277 pkgAcqMetaBase
* const TransactionManager
,
2278 IndexTarget
const Target
)
2279 : pkgAcqBaseIndex(Owner
, TransactionManager
, Target
)
2281 // autoselect the compression method
2282 AutoSelectCompression();
2283 Init(Target
.URI
, Target
.Description
, Target
.ShortDesc
);
2285 if(_config
->FindB("Debug::Acquire::Transaction", false) == true)
2286 std::clog
<< "New pkgIndex with TransactionManager "
2287 << TransactionManager
<< std::endl
;
2290 // AcqIndex::AutoSelectCompression - Select compression /*{{{*/
2291 void pkgAcqIndex::AutoSelectCompression()
2293 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
2294 CompressionExtensions
= "";
2295 if (TransactionManager
->MetaIndexParser
!= NULL
&& TransactionManager
->MetaIndexParser
->Exists(Target
.MetaKey
))
2297 for (std::vector
<std::string
>::const_iterator t
= types
.begin();
2298 t
!= types
.end(); ++t
)
2300 std::string CompressedMetaKey
= string(Target
.MetaKey
).append(".").append(*t
);
2301 if (*t
== "uncompressed" ||
2302 TransactionManager
->MetaIndexParser
->Exists(CompressedMetaKey
) == true)
2303 CompressionExtensions
.append(*t
).append(" ");
2308 for (std::vector
<std::string
>::const_iterator t
= types
.begin(); t
!= types
.end(); ++t
)
2309 CompressionExtensions
.append(*t
).append(" ");
2311 if (CompressionExtensions
.empty() == false)
2312 CompressionExtensions
.erase(CompressionExtensions
.end()-1);
2315 // AcqIndex::Init - defered Constructor /*{{{*/
2316 void pkgAcqIndex::Init(string
const &URI
, string
const &URIDesc
,
2317 string
const &ShortDesc
)
2319 Stage
= STAGE_DOWNLOAD
;
2321 DestFile
= GetPartialFileNameFromURI(URI
);
2323 size_t const nextExt
= CompressionExtensions
.find(' ');
2324 if (nextExt
== std::string::npos
)
2326 CurrentCompressionExtension
= CompressionExtensions
;
2327 CompressionExtensions
.clear();
2331 CurrentCompressionExtension
= CompressionExtensions
.substr(0, nextExt
);
2332 CompressionExtensions
= CompressionExtensions
.substr(nextExt
+1);
2335 if (CurrentCompressionExtension
== "uncompressed")
2339 else if (unlikely(CurrentCompressionExtension
.empty()))
2343 Desc
.URI
= URI
+ '.' + CurrentCompressionExtension
;
2344 DestFile
= DestFile
+ '.' + CurrentCompressionExtension
;
2347 if(TransactionManager
->MetaIndexParser
!= NULL
)
2348 InitByHashIfNeeded();
2350 Desc
.Description
= URIDesc
;
2352 Desc
.ShortDesc
= ShortDesc
;
2357 // AcqIndex::AdjustForByHash - modify URI for by-hash support /*{{{*/
2358 void pkgAcqIndex::InitByHashIfNeeded()
2361 // - (maybe?) add support for by-hash into the sources.list as flag
2362 // - make apt-ftparchive generate the hashes (and expire?)
2363 std::string HostKnob
= "APT::Acquire::" + ::URI(Desc
.URI
).Host
+ "::By-Hash";
2364 if(_config
->FindB("APT::Acquire::By-Hash", false) == true ||
2365 _config
->FindB(HostKnob
, false) == true ||
2366 TransactionManager
->MetaIndexParser
->GetSupportsAcquireByHash())
2368 HashStringList
const Hashes
= GetExpectedHashes();
2371 // FIXME: should we really use the best hash here? or a fixed one?
2372 HashString
const * const TargetHash
= Hashes
.find("");
2373 std::string
const ByHash
= "/by-hash/" + TargetHash
->HashType() + "/" + TargetHash
->HashValue();
2374 size_t const trailing_slash
= Desc
.URI
.find_last_of("/");
2375 Desc
.URI
= Desc
.URI
.replace(
2377 Desc
.URI
.substr(trailing_slash
+1).size()+1,
2381 "Fetching ByHash requested but can not find record for %s",
2382 GetMetaKey().c_str());
2387 // AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
2388 // ---------------------------------------------------------------------
2389 /* The only header we use is the last-modified header. */
2390 string
pkgAcqIndex::Custom600Headers() const
2392 string Final
= GetFinalFilename();
2394 string msg
= "\nIndex-File: true";
2396 if (stat(Final
.c_str(),&Buf
) == 0)
2397 msg
+= "\nLast-Modified: " + TimeRFC1123(Buf
.st_mtime
);
2399 if(Target
.IsOptional
)
2400 msg
+= "\nFail-Ignore: true";
2405 // AcqIndex::Failed - getting the indexfile failed /*{{{*/
2406 void pkgAcqIndex::Failed(string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
)
2408 Item::Failed(Message
,Cnf
);
2410 // authorisation matches will not be fixed by other compression types
2411 if (Status
!= StatAuthError
)
2413 if (CompressionExtensions
.empty() == false)
2415 Init(Target
.URI
, Desc
.Description
, Desc
.ShortDesc
);
2421 if(Target
.IsOptional
&& GetExpectedHashes().empty() && Stage
== STAGE_DOWNLOAD
)
2424 TransactionManager
->AbortTransaction();
2427 // AcqIndex::ReverifyAfterIMS - Reverify index after an ims-hit /*{{{*/
2428 void pkgAcqIndex::ReverifyAfterIMS()
2430 // update destfile to *not* include the compression extension when doing
2431 // a reverify (as its uncompressed on disk already)
2432 DestFile
= GetCompressedFileName(Target
.URI
, GetPartialFileNameFromURI(Target
.URI
), CurrentCompressionExtension
);
2434 // copy FinalFile into partial/ so that we check the hash again
2435 string FinalFile
= GetFinalFilename();
2436 Stage
= STAGE_DECOMPRESS_AND_VERIFY
;
2437 Desc
.URI
= "copy:" + FinalFile
;
2441 // AcqIndex::Done - Finished a fetch /*{{{*/
2442 // ---------------------------------------------------------------------
2443 /* This goes through a number of states.. On the initial fetch the
2444 method could possibly return an alternate filename which points
2445 to the uncompressed version of the file. If this is so the file
2446 is copied into the partial directory. In all other cases the file
2447 is decompressed with a compressed uri. */
2448 void pkgAcqIndex::Done(string
const &Message
,
2449 HashStringList
const &Hashes
,
2450 pkgAcquire::MethodConfig
const * const Cfg
)
2452 Item::Done(Message
,Hashes
,Cfg
);
2456 case STAGE_DOWNLOAD
:
2457 StageDownloadDone(Message
, Hashes
, Cfg
);
2459 case STAGE_DECOMPRESS_AND_VERIFY
:
2460 StageDecompressDone(Message
, Hashes
, Cfg
);
2465 // AcqIndex::StageDownloadDone - Queue for decompress and verify /*{{{*/
2466 void pkgAcqIndex::StageDownloadDone(string
const &Message
, HashStringList
const &,
2467 pkgAcquire::MethodConfig
const * const)
2471 // Handle the unzipd case
2472 string FileName
= LookupTag(Message
,"Alt-Filename");
2473 if (FileName
.empty() == false)
2475 Stage
= STAGE_DECOMPRESS_AND_VERIFY
;
2477 DestFile
+= ".decomp";
2478 Desc
.URI
= "copy:" + FileName
;
2480 SetActiveSubprocess("copy");
2484 FileName
= LookupTag(Message
,"Filename");
2485 if (FileName
.empty() == true)
2488 ErrorText
= "Method gave a blank filename";
2491 // Methods like e.g. "file:" will give us a (compressed) FileName that is
2492 // not the "DestFile" we set, in this case we uncompress from the local file
2493 if (FileName
!= DestFile
)
2496 EraseFileName
= FileName
;
2498 // we need to verify the file against the current Release file again
2499 // on if-modfied-since hit to avoid a stale attack against us
2500 if(StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
2502 // The files timestamp matches, reverify by copy into partial/
2508 // If we have compressed indexes enabled, queue for hash verification
2509 if (_config
->FindB("Acquire::GzipIndexes",false))
2511 DestFile
= GetPartialFileNameFromURI(Target
.URI
+ '.' + CurrentCompressionExtension
);
2513 Stage
= STAGE_DECOMPRESS_AND_VERIFY
;
2514 Desc
.URI
= "copy:" + FileName
;
2516 SetActiveSubprocess("copy");
2520 // get the binary name for your used compression type
2522 if(CurrentCompressionExtension
== "uncompressed")
2523 decompProg
= "copy";
2525 decompProg
= _config
->Find(string("Acquire::CompressionTypes::").append(CurrentCompressionExtension
),"");
2526 if(decompProg
.empty() == true)
2528 _error
->Error("Unsupported extension: %s", CurrentCompressionExtension
.c_str());
2532 // queue uri for the next stage
2533 Stage
= STAGE_DECOMPRESS_AND_VERIFY
;
2534 DestFile
+= ".decomp";
2535 Desc
.URI
= decompProg
+ ":" + FileName
;
2537 SetActiveSubprocess(decompProg
);
2540 // AcqIndex::StageDecompressDone - Final verification /*{{{*/
2541 void pkgAcqIndex::StageDecompressDone(string
const &,
2542 HashStringList
const &,
2543 pkgAcquire::MethodConfig
const * const)
2545 // Done, queue for rename on transaction finished
2546 TransactionManager
->TransactionStageCopy(this, DestFile
, GetFinalFilename());
2552 // AcqArchive::AcqArchive - Constructor /*{{{*/
2553 // ---------------------------------------------------------------------
2554 /* This just sets up the initial fetch environment and queues the first
2556 pkgAcqArchive::pkgAcqArchive(pkgAcquire
* const Owner
,pkgSourceList
* const Sources
,
2557 pkgRecords
* const Recs
,pkgCache::VerIterator
const &Version
,
2558 string
&StoreFilename
) :
2559 Item(Owner
), LocalSource(false), Version(Version
), Sources(Sources
), Recs(Recs
),
2560 StoreFilename(StoreFilename
), Vf(Version
.FileList()),
2563 Retries
= _config
->FindI("Acquire::Retries",0);
2565 if (Version
.Arch() == 0)
2567 _error
->Error(_("I wasn't able to locate a file for the %s package. "
2568 "This might mean you need to manually fix this package. "
2569 "(due to missing arch)"),
2570 Version
.ParentPkg().FullName().c_str());
2574 /* We need to find a filename to determine the extension. We make the
2575 assumption here that all the available sources for this version share
2576 the same extension.. */
2577 // Skip not source sources, they do not have file fields.
2578 for (; Vf
.end() == false; ++Vf
)
2580 if ((Vf
.File()->Flags
& pkgCache::Flag::NotSource
) != 0)
2585 // Does not really matter here.. we are going to fail out below
2586 if (Vf
.end() != true)
2588 // If this fails to get a file name we will bomb out below.
2589 pkgRecords::Parser
&Parse
= Recs
->Lookup(Vf
);
2590 if (_error
->PendingError() == true)
2593 // Generate the final file name as: package_version_arch.foo
2594 StoreFilename
= QuoteString(Version
.ParentPkg().Name(),"_:") + '_' +
2595 QuoteString(Version
.VerStr(),"_:") + '_' +
2596 QuoteString(Version
.Arch(),"_:.") +
2597 "." + flExtension(Parse
.FileName());
2600 // check if we have one trusted source for the package. if so, switch
2601 // to "TrustedOnly" mode - but only if not in AllowUnauthenticated mode
2602 bool const allowUnauth
= _config
->FindB("APT::Get::AllowUnauthenticated", false);
2603 bool const debugAuth
= _config
->FindB("Debug::pkgAcquire::Auth", false);
2604 bool seenUntrusted
= false;
2605 for (pkgCache::VerFileIterator i
= Version
.FileList(); i
.end() == false; ++i
)
2607 pkgIndexFile
*Index
;
2608 if (Sources
->FindIndex(i
.File(),Index
) == false)
2611 if (debugAuth
== true)
2612 std::cerr
<< "Checking index: " << Index
->Describe()
2613 << "(Trusted=" << Index
->IsTrusted() << ")" << std::endl
;
2615 if (Index
->IsTrusted() == true)
2618 if (allowUnauth
== false)
2622 seenUntrusted
= true;
2625 // "allow-unauthenticated" restores apts old fetching behaviour
2626 // that means that e.g. unauthenticated file:// uris are higher
2627 // priority than authenticated http:// uris
2628 if (allowUnauth
== true && seenUntrusted
== true)
2632 if (QueueNext() == false && _error
->PendingError() == false)
2633 _error
->Error(_("Can't find a source to download version '%s' of '%s'"),
2634 Version
.VerStr(), Version
.ParentPkg().FullName(false).c_str());
2637 // AcqArchive::QueueNext - Queue the next file source /*{{{*/
2638 // ---------------------------------------------------------------------
2639 /* This queues the next available file version for download. It checks if
2640 the archive is already available in the cache and stashs the MD5 for
2642 bool pkgAcqArchive::QueueNext()
2644 for (; Vf
.end() == false; ++Vf
)
2646 pkgCache::PkgFileIterator
const PkgF
= Vf
.File();
2647 // Ignore not source sources
2648 if ((PkgF
->Flags
& pkgCache::Flag::NotSource
) != 0)
2651 // Try to cross match against the source list
2652 pkgIndexFile
*Index
;
2653 if (Sources
->FindIndex(PkgF
, Index
) == false)
2655 LocalSource
= (PkgF
->Flags
& pkgCache::Flag::LocalSource
) == pkgCache::Flag::LocalSource
;
2657 // only try to get a trusted package from another source if that source
2659 if(Trusted
&& !Index
->IsTrusted())
2662 // Grab the text package record
2663 pkgRecords::Parser
&Parse
= Recs
->Lookup(Vf
);
2664 if (_error
->PendingError() == true)
2667 string PkgFile
= Parse
.FileName();
2668 ExpectedHashes
= Parse
.Hashes();
2670 if (PkgFile
.empty() == true)
2671 return _error
->Error(_("The package index files are corrupted. No Filename: "
2672 "field for package %s."),
2673 Version
.ParentPkg().Name());
2675 Desc
.URI
= Index
->ArchiveURI(PkgFile
);
2676 Desc
.Description
= Index
->ArchiveInfo(Version
);
2678 Desc
.ShortDesc
= Version
.ParentPkg().FullName(true);
2680 // See if we already have the file. (Legacy filenames)
2681 FileSize
= Version
->Size
;
2682 string FinalFile
= _config
->FindDir("Dir::Cache::Archives") + flNotDir(PkgFile
);
2684 if (stat(FinalFile
.c_str(),&Buf
) == 0)
2686 // Make sure the size matches
2687 if ((unsigned long long)Buf
.st_size
== Version
->Size
)
2692 StoreFilename
= DestFile
= FinalFile
;
2696 /* Hmm, we have a file and its size does not match, this means it is
2697 an old style mismatched arch */
2698 unlink(FinalFile
.c_str());
2701 // Check it again using the new style output filenames
2702 FinalFile
= _config
->FindDir("Dir::Cache::Archives") + flNotDir(StoreFilename
);
2703 if (stat(FinalFile
.c_str(),&Buf
) == 0)
2705 // Make sure the size matches
2706 if ((unsigned long long)Buf
.st_size
== Version
->Size
)
2711 StoreFilename
= DestFile
= FinalFile
;
2715 /* Hmm, we have a file and its size does not match, this shouldn't
2717 unlink(FinalFile
.c_str());
2720 DestFile
= _config
->FindDir("Dir::Cache::Archives") + "partial/" + flNotDir(StoreFilename
);
2722 // Check the destination file
2723 if (stat(DestFile
.c_str(),&Buf
) == 0)
2725 // Hmm, the partial file is too big, erase it
2726 if ((unsigned long long)Buf
.st_size
> Version
->Size
)
2727 unlink(DestFile
.c_str());
2729 PartialSize
= Buf
.st_size
;
2732 // Disables download of archives - useful if no real installation follows,
2733 // e.g. if we are just interested in proposed installation order
2734 if (_config
->FindB("Debug::pkgAcqArchive::NoQueue", false) == true)
2739 StoreFilename
= DestFile
= FinalFile
;
2753 // AcqArchive::Done - Finished fetching /*{{{*/
2754 // ---------------------------------------------------------------------
2756 void pkgAcqArchive::Done(string
const &Message
, HashStringList
const &Hashes
,
2757 pkgAcquire::MethodConfig
const * const Cfg
)
2759 Item::Done(Message
, Hashes
, Cfg
);
2761 // Grab the output filename
2762 string FileName
= LookupTag(Message
,"Filename");
2763 if (FileName
.empty() == true)
2766 ErrorText
= "Method gave a blank filename";
2770 // Reference filename
2771 if (FileName
!= DestFile
)
2773 StoreFilename
= DestFile
= FileName
;
2779 // Done, move it into position
2780 string
const FinalFile
= GetFinalFilename();
2781 Rename(DestFile
,FinalFile
);
2782 StoreFilename
= DestFile
= FinalFile
;
2786 // AcqArchive::Failed - Failure handler /*{{{*/
2787 // ---------------------------------------------------------------------
2788 /* Here we try other sources */
2789 void pkgAcqArchive::Failed(string
const &Message
,pkgAcquire::MethodConfig
const * const Cnf
)
2791 Item::Failed(Message
,Cnf
);
2793 /* We don't really want to retry on failed media swaps, this prevents
2794 that. An interesting observation is that permanent failures are not
2796 if (Cnf
->Removable
== true &&
2797 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
2799 // Vf = Version.FileList();
2800 while (Vf
.end() == false) ++Vf
;
2801 StoreFilename
= string();
2806 if (QueueNext() == false)
2808 // This is the retry counter
2810 Cnf
->LocalOnly
== false &&
2811 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
2814 Vf
= Version
.FileList();
2815 if (QueueNext() == true)
2819 StoreFilename
= string();
2824 APT_PURE
bool pkgAcqArchive::IsTrusted() const /*{{{*/
2829 void pkgAcqArchive::Finished() /*{{{*/
2831 if (Status
== pkgAcquire::Item::StatDone
&&
2834 StoreFilename
= string();
2837 std::string
pkgAcqArchive::DescURI() const /*{{{*/
2842 std::string
pkgAcqArchive::ShortDesc() const /*{{{*/
2844 return Desc
.ShortDesc
;
2848 // AcqFile::pkgAcqFile - Constructor /*{{{*/
2849 pkgAcqFile::pkgAcqFile(pkgAcquire
* const Owner
,string
const &URI
, HashStringList
const &Hashes
,
2850 unsigned long long const Size
,string
const &Dsc
,string
const &ShortDesc
,
2851 const string
&DestDir
, const string
&DestFilename
,
2852 bool const IsIndexFile
) :
2853 Item(Owner
), IsIndexFile(IsIndexFile
), ExpectedHashes(Hashes
)
2855 Retries
= _config
->FindI("Acquire::Retries",0);
2857 if(!DestFilename
.empty())
2858 DestFile
= DestFilename
;
2859 else if(!DestDir
.empty())
2860 DestFile
= DestDir
+ "/" + flNotDir(URI
);
2862 DestFile
= flNotDir(URI
);
2866 Desc
.Description
= Dsc
;
2869 // Set the short description to the archive component
2870 Desc
.ShortDesc
= ShortDesc
;
2872 // Get the transfer sizes
2875 if (stat(DestFile
.c_str(),&Buf
) == 0)
2877 // Hmm, the partial file is too big, erase it
2878 if ((Size
> 0) && (unsigned long long)Buf
.st_size
> Size
)
2879 unlink(DestFile
.c_str());
2881 PartialSize
= Buf
.st_size
;
2887 // AcqFile::Done - Item downloaded OK /*{{{*/
2888 void pkgAcqFile::Done(string
const &Message
,HashStringList
const &CalcHashes
,
2889 pkgAcquire::MethodConfig
const * const Cnf
)
2891 Item::Done(Message
,CalcHashes
,Cnf
);
2893 string FileName
= LookupTag(Message
,"Filename");
2894 if (FileName
.empty() == true)
2897 ErrorText
= "Method gave a blank filename";
2903 // The files timestamp matches
2904 if (StringToBool(LookupTag(Message
,"IMS-Hit"),false) == true)
2907 // We have to copy it into place
2908 if (FileName
!= DestFile
)
2911 if (_config
->FindB("Acquire::Source-Symlinks",true) == false ||
2912 Cnf
->Removable
== true)
2914 Desc
.URI
= "copy:" + FileName
;
2919 // Erase the file if it is a symlink so we can overwrite it
2921 if (lstat(DestFile
.c_str(),&St
) == 0)
2923 if (S_ISLNK(St
.st_mode
) != 0)
2924 unlink(DestFile
.c_str());
2928 if (symlink(FileName
.c_str(),DestFile
.c_str()) != 0)
2930 _error
->PushToStack();
2931 _error
->Errno("pkgAcqFile::Done", "Symlinking file %s failed", DestFile
.c_str());
2932 std::stringstream msg
;
2933 _error
->DumpErrors(msg
);
2934 _error
->RevertToStack();
2935 ErrorText
= msg
.str();
2942 // AcqFile::Failed - Failure handler /*{{{*/
2943 // ---------------------------------------------------------------------
2944 /* Here we try other sources */
2945 void pkgAcqFile::Failed(string
const &Message
, pkgAcquire::MethodConfig
const * const Cnf
)
2947 Item::Failed(Message
,Cnf
);
2949 // This is the retry counter
2951 Cnf
->LocalOnly
== false &&
2952 StringToBool(LookupTag(Message
,"Transient-Failure"),false) == true)
2962 string
pkgAcqFile::Custom600Headers() const /*{{{*/
2965 return "\nIndex-File: true";