]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-item.cc
create directory for extended_states if needed
[apt.git] / apt-pkg / acquire-item.cc
index 11c522ae54c5a7ce9dd8bbd9cece175cd82f9ce3..dd85fda79e112df34a13458ed8a6cf0cbff8496a 100644 (file)
@@ -44,9 +44,6 @@
 #include <sstream>
 #include <stdio.h>
 #include <ctime>
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -65,20 +62,6 @@ static void printHashSumComparision(std::string const &URI, HashStringList const
       std::cerr <<  "\t- " << hs->toStr() << std::endl;
 }
                                                                        /*}}}*/
-static void ChangeOwnerAndPermissionOfFile(char const * const requester, char const * const file, char const * const user, char const * const group, mode_t const mode) /*{{{*/
-{
-   if (getuid() == 0 && strlen(user) != 0 && strlen(group) != 0) // if we aren't root, we can't chown, so don't try it
-   {
-      // ensure the file is owned by root and has good permissions
-      struct passwd const * const pw = getpwnam(user);
-      struct group const * const gr = getgrnam(group);
-      if (pw != NULL && gr != NULL && chown(file, pw->pw_uid, gr->gr_gid) != 0)
-        _error->WarningE(requester, "chown to %s:%s of file %s failed", user, group, file);
-   }
-   if (chmod(file, mode) != 0)
-      _error->WarningE(requester, "chmod 0%o of file %s failed", mode, file);
-}
-                                                                       /*}}}*/
 static std::string GetPartialFileName(std::string const &file)         /*{{{*/
 {
    std::string DestFile = _config->FindDir("Dir::State::lists") + "partial/";
@@ -121,10 +104,7 @@ static bool AllowInsecureRepositories(indexRecords const * const MetaIndexParser
 
 
 // Acquire::Item::Item - Constructor                                   /*{{{*/
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
+APT_IGNORE_DEPRECATED_PUSH
 pkgAcquire::Item::Item(pkgAcquire *Owner,
                        HashStringList const &ExpectedHashes,
                        pkgAcqMetaBase *TransactionManager)
@@ -137,9 +117,7 @@ pkgAcquire::Item::Item(pkgAcquire *Owner,
    if(TransactionManager != NULL)
       TransactionManager->Add(this);
 }
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+APT_IGNORE_DEPRECATED_POP
                                                                        /*}}}*/
 // Acquire::Item::~Item - Destructor                                   /*{{{*/
 // ---------------------------------------------------------------------
@@ -155,9 +133,6 @@ pkgAcquire::Item::~Item()
    fetch this object */
 void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
 {
-   if (RealFileExists(DestFile))
-      ChangeOwnerAndPermissionOfFile("Item::Failed", DestFile.c_str(), "root", "root", 0644);
-
    if(ErrorText.empty())
       ErrorText = LookupTag(Message,"Message");
    UsedMirror =  LookupTag(Message,"UsedMirror");
@@ -219,8 +194,6 @@ void pkgAcquire::Item::Done(string Message,unsigned long long Size,HashStringLis
       if (Owner->Log != 0)
         Owner->Log->Fetched(Size,atoi(LookupTag(Message,"Resume-Point","0").c_str()));
    }
-   if (RealFileExists(DestFile))
-      ChangeOwnerAndPermissionOfFile("Item::Done", DestFile.c_str(), "root", "root", 0644);
 
    if (FileSize == 0)
       FileSize= Size;
@@ -237,7 +210,6 @@ bool pkgAcquire::Item::Rename(string From,string To)
 {
    if (rename(From.c_str(),To.c_str()) == 0)
       return true;
-   ChangeOwnerAndPermissionOfFile("Item::Failed", To.c_str(), "root", "root", 0644);
 
    std::string S;
    strprintf(S, _("rename failed, %s (%s -> %s)."), strerror(errno),
@@ -249,12 +221,6 @@ bool pkgAcquire::Item::Rename(string From,string To)
                                                                        /*}}}*/
 void pkgAcquire::Item::QueueURI(ItemDesc &Item)                                /*{{{*/
 {
-   if (RealFileExists(DestFile))
-   {
-      std::string SandboxUser = _config->Find("APT::Sandbox::User");
-      ChangeOwnerAndPermissionOfFile("Item::QueueURI", DestFile.c_str(),
-                                     SandboxUser.c_str(), "root", 0600);
-   }
    Owner->Enqueue(Item);
 }
                                                                        /*}}}*/
@@ -304,14 +270,7 @@ bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState const
 void pkgAcquire::Item::SetActiveSubprocess(const std::string &subprocess)/*{{{*/
 {
       ActiveSubprocess = subprocess;
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic push
-       #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-#endif
-        Mode = ActiveSubprocess.c_str();
-#if __GNUC__ >= 4
-       #pragma GCC diagnostic pop
-#endif
+      APT_IGNORE_DEPRECATED(Mode = ActiveSubprocess.c_str();)
 }
                                                                        /*}}}*/
 // Acquire::Item::ReportMirrorFailure                                  /*{{{*/
@@ -414,7 +373,11 @@ pkgAcqDiffIndex::pkgAcqDiffIndex(pkgAcquire *Owner,
 // AcqIndex::Custom600Headers - Insert custom request headers          /*{{{*/
 // ---------------------------------------------------------------------
 /* The only header we use is the last-modified header. */
+#if APT_PKG_ABI >= 413
 string pkgAcqDiffIndex::Custom600Headers() const
+#else
+string pkgAcqDiffIndex::Custom600Headers()
+#endif
 {
    string Final = _config->FindDir("Dir::State::lists");
    Final += URItoFileName(Desc.URI);
@@ -648,7 +611,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string IndexDiffFile)          /*{{{*/
         cur != available_patches.end(); ++cur)
       patchesSize += cur->patch_size;
    unsigned long long const sizeLimit = ServerSize * _config->FindI("Acquire::PDiffs::SizeLimit", 100);
-   if (false && sizeLimit > 0 && (sizeLimit/100) < patchesSize)
+   if (sizeLimit > 0 && (sizeLimit/100) < patchesSize)
    {
       if (Debug)
         std::clog << "Need " << patchesSize << " bytes (Limit is " << sizeLimit/100
@@ -1280,7 +1243,11 @@ void pkgAcqIndex::InitByHashIfNeeded(const std::string MetaKey)
 // AcqIndex::Custom600Headers - Insert custom request headers          /*{{{*/
 // ---------------------------------------------------------------------
 /* The only header we use is the last-modified header. */
+#if APT_PKG_ABI >= 413
 string pkgAcqIndex::Custom600Headers() const
+#else
+string pkgAcqIndex::Custom600Headers()
+#endif
 {
    string Final = GetFinalFilename();
 
@@ -1289,6 +1256,9 @@ string pkgAcqIndex::Custom600Headers() const
    if (stat(Final.c_str(),&Buf) == 0)
       msg += "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
 
+   if(Target->IsOptional())
+      msg += "\nFail-Ignore: true";
+
    return msg;
 }
                                                                        /*}}}*/
@@ -1312,8 +1282,12 @@ void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
       unlink(EraseFileName.c_str());
    }
 
-   /// cancel the entire transaction
-   TransactionManager->AbortTransaction();
+   Item::Failed(Message,Cnf);
+
+   if(Target->IsOptional() && ExpectedHashes.empty() && Stage == STAGE_DOWNLOAD)
+      Status = StatDone;
+   else
+      TransactionManager->AbortTransaction();
 }
                                                                        /*}}}*/
 // pkgAcqIndex::GetFinalFilename - Return the full final file path     /*{{{*/
@@ -1505,57 +1479,6 @@ void pkgAcqIndex::StageDecompressDone(string Message,
    return;
 }
                                                                        /*}}}*/
-// AcqIndexTrans::pkgAcqIndexTrans - Constructor                       /*{{{*/
-// ---------------------------------------------------------------------
-/* The Translation file is added to the queue */
-pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner,
-                           string URI,string URIDesc,string ShortDesc)
-  : pkgAcqIndex(Owner, URI, URIDesc, ShortDesc, HashStringList())
-{
-}
-pkgAcqIndexTrans::pkgAcqIndexTrans(pkgAcquire *Owner,
-                                   pkgAcqMetaBase *TransactionManager,
-                                   IndexTarget const * const Target,
-                                   HashStringList const &ExpectedHashes,
-                                   indexRecords *MetaIndexParser)
-   : pkgAcqIndex(Owner, TransactionManager, Target, ExpectedHashes, MetaIndexParser)
-{
-}
-                                                                       /*}}}*/
-// AcqIndexTrans::Custom600Headers - Insert custom request headers     /*{{{*/
-string pkgAcqIndexTrans::Custom600Headers() const
-{
-   string Final = GetFinalFilename();
-
-   struct stat Buf;
-   if (stat(Final.c_str(),&Buf) != 0)
-      return "\nFail-Ignore: true\nIndex-File: true";
-   return "\nFail-Ignore: true\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
-}
-                                                                       /*}}}*/
-// AcqIndexTrans::Failed - Silence failure messages for missing files  /*{{{*/
-void pkgAcqIndexTrans::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
-{
-   Item::Failed(Message,Cnf);
-
-   size_t const nextExt = CompressionExtensions.find(' ');
-   if (nextExt != std::string::npos)
-   {
-      CompressionExtensions = CompressionExtensions.substr(nextExt+1);
-      Init(RealURI, Desc.Description, Desc.ShortDesc);
-      Status = StatIdle;
-      return;
-   }
-
-   // FIXME: this is used often (e.g. in pkgAcqIndexTrans) so refactor
-   if (Cnf->LocalOnly == true ||
-       StringToBool(LookupTag(Message,"Transient-Failure"),false) == false)
-   {
-      // Ignore this
-      Status = StatDone;
-   }
-}
-                                                                       /*}}}*/
 // AcqMetaBase::Add - Add a item to the current Transaction            /*{{{*/
 void pkgAcqMetaBase::Add(Item *I)
 {
@@ -1576,12 +1499,10 @@ void pkgAcqMetaBase::AbortTransaction()
          std::clog << "  Cancel: " << (*I)->DestFile << std::endl;
       // the transaction will abort, so stop anything that is idle
       if ((*I)->Status == pkgAcquire::Item::StatIdle)
+      {
          (*I)->Status = pkgAcquire::Item::StatDone;
-
-      // reverify might act on a file outside of partial
-      // (as it itself is good, but needed to verify others, like Release)
-      if ((*I)->DestFile == (*I)->PartialFile && RealFileExists((*I)->DestFile))
-        ChangeOwnerAndPermissionOfFile("AbortTransaction", (*I)->DestFile.c_str(), "root", "root", 0644);
+         (*I)->Dequeue();
+      }
    }
    Transaction.clear();
 }
@@ -1725,7 +1646,11 @@ pkgAcqMetaSig::~pkgAcqMetaSig()                                          /*{{{*/
                                                                        /*}}}*/
 // pkgAcqMetaSig::Custom600Headers - Insert custom request headers     /*{{{*/
 // ---------------------------------------------------------------------
+#if APT_PKG_ABI >= 413
 string pkgAcqMetaSig::Custom600Headers() const
+#else
+string pkgAcqMetaSig::Custom600Headers()
+#endif
 {
    std::string Header = GetCustom600Headers(RealURI);
    return Header;
@@ -1870,7 +1795,11 @@ void pkgAcqMetaIndex::Init(std::string URIDesc, std::string ShortDesc)
                                                                        /*}}}*/
 // pkgAcqMetaIndex::Custom600Headers - Insert custom request headers   /*{{{*/
 // ---------------------------------------------------------------------
+#if APT_PKG_ABI >= 413
 string pkgAcqMetaIndex::Custom600Headers() const
+#else
+string pkgAcqMetaIndex::Custom600Headers()
+#endif
 {
    return GetCustom600Headers(RealURI);
 }
@@ -2004,87 +1933,59 @@ bool pkgAcqMetaBase::CheckDownloadDone(const std::string &Message,
                                                                        /*}}}*/
 void pkgAcqMetaBase::QueueIndexes(bool verify)                         /*{{{*/
 {
-   bool transInRelease = false;
-   {
-      std::vector<std::string> const keys = MetaIndexParser->MetaKeys();
-      for (std::vector<std::string>::const_iterator k = keys.begin(); k != keys.end(); ++k)
-        // FIXME: Feels wrong to check for hardcoded string here, but what should we do elseā€¦
-        if (k->find("Translation-") != std::string::npos)
-        {
-           transInRelease = true;
-           break;
-        }
-   }
-
    // at this point the real Items are loaded in the fetcher
    ExpectedAdditionalItems = 0;
-   for (vector <IndexTarget*>::const_iterator Target = IndexTargets->begin();
+
+   vector <struct IndexTarget*>::const_iterator Target;
+   for (Target = IndexTargets->begin();
         Target != IndexTargets->end();
         ++Target)
    {
       HashStringList ExpectedIndexHashes;
       const indexRecords::checkSum *Record = MetaIndexParser->Lookup((*Target)->MetaKey);
-      bool compressedAvailable = false;
-      if (Record == NULL)
+
+      // optional target that we do not have in the Release file are 
+      // skipped
+      if (verify == true && Record == NULL && (*Target)->IsOptional())
+         continue;
+
+      // targets without a hash record are a error when verify is required
+      if (verify == true && Record == NULL)
       {
-        if ((*Target)->IsOptional() == true)
-        {
-           std::vector<std::string> types = APT::Configuration::getCompressionTypes();
-           for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
-              if (MetaIndexParser->Exists((*Target)->MetaKey + "." + *t) == true)
-              {
-                 compressedAvailable = true;
-                 break;
-              }
-        }
-        else if (verify == true)
-        {
-           Status = StatAuthError;
-           strprintf(ErrorText, _("Unable to find expected entry '%s' in Release file (Wrong sources.list entry or malformed file)"), (*Target)->MetaKey.c_str());
-           return;
-        }
+         Status = StatAuthError;
+         strprintf(ErrorText, _("Unable to find expected entry '%s' in Release file (Wrong sources.list entry or malformed file)"), (*Target)->MetaKey.c_str());
+         return;
       }
-      else
+
+      if (Record)
+         ExpectedIndexHashes = Record->Hashes;
+      
+      if (_config->FindB("Debug::pkgAcquire::Auth", false))
       {
-        ExpectedIndexHashes = Record->Hashes;
-        if (_config->FindB("Debug::pkgAcquire::Auth", false))
-        {
-           std::cerr << "Queueing: " << (*Target)->URI << std::endl
-              << "Expected Hash:" << std::endl;
-           for (HashStringList::const_iterator hs = ExpectedIndexHashes.begin(); hs != ExpectedIndexHashes.end(); ++hs)
-              std::cerr <<  "\t- " << hs->toStr() << std::endl;
-           std::cerr << "For: " << Record->MetaKeyFilename << std::endl;
-        }
-        if (verify == true && ExpectedIndexHashes.empty() == true && (*Target)->IsOptional() == false)
-        {
-           Status = StatAuthError;
-           strprintf(ErrorText, _("Unable to find hash sum for '%s' in Release file"), (*Target)->MetaKey.c_str());
-           return;
-        }
-      }
+         std::cerr << "Queueing: " << (*Target)->URI << std::endl
+                   << "Expected Hash:" << std::endl;
+         for (HashStringList::const_iterator hs = ExpectedIndexHashes.begin(); hs != ExpectedIndexHashes.end(); ++hs)
+            std::cerr <<  "\t- " << hs->toStr() << std::endl;
+         std::cerr << "For: " << Record->MetaKeyFilename << std::endl;
 
-      if ((*Target)->IsOptional() == true)
+      }
+      if (verify == true && ExpectedIndexHashes.empty() == true)
       {
-        if (transInRelease == false || Record != NULL || compressedAvailable == true)
-        {
-           if (_config->FindB("Acquire::PDiffs",true) == true && transInRelease == true &&
-               MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true)
-              new pkgAcqDiffIndex(Owner, TransactionManager, *Target, ExpectedIndexHashes, MetaIndexParser);
-           else
-              new pkgAcqIndexTrans(Owner, TransactionManager, *Target, ExpectedIndexHashes, MetaIndexParser);
-        }
-        continue;
+         Status = StatAuthError;
+         strprintf(ErrorText, _("Unable to find hash sum for '%s' in Release file"), (*Target)->MetaKey.c_str());
+         return;
       }
 
-      /* Queue Packages file (either diff or full packages files, depending
+      /* Queue the Index file (Packages, Sources, Translation-$foo
+         (either diff or full packages files, depending
          on the users option) - we also check if the PDiff Index file is listed
          in the Meta-Index file. Ideal would be if pkgAcqDiffIndex would test this
          instead, but passing the required info to it is to much hassle */
       if(_config->FindB("Acquire::PDiffs",true) == true && (verify == false ||
-         MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true))
-        new pkgAcqDiffIndex(Owner, TransactionManager, *Target, ExpectedIndexHashes, MetaIndexParser);
+          MetaIndexParser->Exists((*Target)->MetaKey + ".diff/Index") == true))
+         new pkgAcqDiffIndex(Owner, TransactionManager, *Target, ExpectedIndexHashes, MetaIndexParser);
       else
-        new pkgAcqIndex(Owner, TransactionManager, *Target, ExpectedIndexHashes, MetaIndexParser);
+         new pkgAcqIndex(Owner, TransactionManager, *Target, ExpectedIndexHashes, MetaIndexParser);
    }
 }
                                                                        /*}}}*/
@@ -2222,7 +2123,11 @@ pkgAcqMetaClearSig::~pkgAcqMetaClearSig()                                /*{{{*/
                                                                        /*}}}*/
 // pkgAcqMetaClearSig::Custom600Headers - Insert custom request headers        /*{{{*/
 // ---------------------------------------------------------------------
+#if APT_PKG_ABI >= 413
 string pkgAcqMetaClearSig::Custom600Headers() const
+#else
+string pkgAcqMetaClearSig::Custom600Headers()
+#endif
 {
    string Header = GetCustom600Headers(RealURI);
    Header += "\nFail-Ignore: true";
@@ -2501,11 +2406,7 @@ bool pkgAcqArchive::QueueNext()
         if ((unsigned long long)Buf.st_size > Version->Size)
            unlink(DestFile.c_str());
         else
-        {
            PartialSize = Buf.st_size;
-            std::string SandboxUser = _config->Find("APT::Sandbox::User");
-           ChangeOwnerAndPermissionOfFile("pkgAcqArchive::QueueNext",DestFile.c_str(), SandboxUser.c_str(), "root", 0600);
-        }
       }
 
       // Disables download of archives - useful if no real installation follows,
@@ -2618,7 +2519,11 @@ void pkgAcqArchive::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
                                                                        /*}}}*/
 // AcqArchive::IsTrusted - Determine whether this archive comes from a trusted source /*{{{*/
 // ---------------------------------------------------------------------
+#if APT_PKG_ABI >= 413
 APT_PURE bool pkgAcqArchive::IsTrusted() const
+#else
+APT_PURE bool pkgAcqArchive::IsTrusted()
+#endif
 {
    return Trusted;
 }
@@ -2669,11 +2574,7 @@ pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI, HashStringList const &Hashe
       if ((Size > 0) && (unsigned long long)Buf.st_size > Size)
         unlink(DestFile.c_str());
       else
-      {
         PartialSize = Buf.st_size;
-         std::string SandboxUser = _config->Find("APT::Sandbox::User");
-        ChangeOwnerAndPermissionOfFile("pkgAcqFile", DestFile.c_str(), SandboxUser.c_str(), "root", 0600);
-      }
    }
 
    QueueURI(Desc);
@@ -2767,7 +2668,11 @@ void pkgAcqFile::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
 // AcqIndex::Custom600Headers - Insert custom request headers          /*{{{*/
 // ---------------------------------------------------------------------
 /* The only header we use is the last-modified header. */
+#if APT_PKG_ABI >= 413
 string pkgAcqFile::Custom600Headers() const
+#else
+string pkgAcqFile::Custom600Headers()
+#endif
 {
    if (IsIndexFile)
       return "\nIndex-File: true";