Quellcode durchsuchen

ignore Acquire::GzipIndexes for cdrom sources

We do not support compressed indexes for cdrom sources as we rewrite
some of them, so supporting it correctly could be hard. What we do
instead in the meantime is probably disabling it for cdrom sources.
David Kalnischkies vor 11 Jahren
Ursprung
Commit
70b63c573f
2 geänderte Dateien mit 52 neuen und 30 gelöschten Zeilen
  1. 27 20
      apt-pkg/acquire-item.cc
  2. 25 10
      test/integration/test-compressed-indexes

+ 27 - 20
apt-pkg/acquire-item.cc

@@ -65,7 +65,7 @@ static void printHashSumComparision(std::string const &URI, HashStringList const
       std::cerr <<  "\t- " << hs->toStr() << std::endl;
       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)
+static void ChangeOwnerAndPermissionOfFile(char const * const requester, char const * const file, char const * const user, char const * const group, mode_t const mode) /*{{{*/
 {
 {
    // ensure the file is owned by root and has good permissions
    // ensure the file is owned by root and has good permissions
    struct passwd const * const pw = getpwnam(user);
    struct passwd const * const pw = getpwnam(user);
@@ -78,17 +78,35 @@ static void ChangeOwnerAndPermissionOfFile(char const * const requester, char co
    if (chmod(file, mode) != 0)
    if (chmod(file, mode) != 0)
       _error->WarningE(requester, "chmod 0%o of file %s failed", mode, file);
       _error->WarningE(requester, "chmod 0%o of file %s failed", mode, file);
 }
 }
-static std::string GetPartialFileName(std::string const &file)
+									/*}}}*/
+static std::string GetPartialFileName(std::string const &file)		/*{{{*/
 {
 {
    std::string DestFile = _config->FindDir("Dir::State::lists") + "partial/";
    std::string DestFile = _config->FindDir("Dir::State::lists") + "partial/";
    DestFile += file;
    DestFile += file;
    return DestFile;
    return DestFile;
 }
 }
-static std::string GetPartialFileNameFromURI(std::string const &uri)
+									/*}}}*/
+static std::string GetPartialFileNameFromURI(std::string const &uri)	/*{{{*/
 {
 {
    return GetPartialFileName(URItoFileName(uri));
    return GetPartialFileName(URItoFileName(uri));
 }
 }
+									/*}}}*/
+static std::string GetCompressedFileName(std::string const &URI, std::string const &Name, std::string const &Ext) /*{{{*/
+{
+   if (Ext.empty() || Ext == "uncompressed")
+      return Name;
+
+   // do not reverify cdrom sources as apt-cdrom may rewrite the Packages
+   // file when its doing the indexcopy
+   if (URI.substr(0,6) == "cdrom:")
+      return Name;
 
 
+   // adjust DestFile if its compressed on disk
+   if (_config->FindB("Acquire::GzipIndexes",false) == true)
+      return Name + '.' + Ext;
+   return Name;
+}
+									/*}}}*/
 
 
 // Acquire::Item::Item - Constructor					/*{{{*/
 // Acquire::Item::Item - Constructor					/*{{{*/
 #if __GNUC__ >= 4
 #if __GNUC__ >= 4
@@ -211,8 +229,7 @@ bool pkgAcquire::Item::Rename(string From,string To)
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
-
-void pkgAcquire::Item::QueueURI(ItemDesc &Item)
+void pkgAcquire::Item::QueueURI(ItemDesc &Item)				/*{{{*/
 {
 {
    if (RealFileExists(DestFile))
    if (RealFileExists(DestFile))
    {
    {
@@ -222,11 +239,12 @@ void pkgAcquire::Item::QueueURI(ItemDesc &Item)
    }
    }
    Owner->Enqueue(Item);
    Owner->Enqueue(Item);
 }
 }
-void pkgAcquire::Item::Dequeue()
+									/*}}}*/
+void pkgAcquire::Item::Dequeue()					/*{{{*/
 {
 {
    Owner->Dequeue(this);
    Owner->Dequeue(this);
 }
 }
-
+									/*}}}*/
 bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState const error)/*{{{*/
 bool pkgAcquire::Item::RenameOnError(pkgAcquire::Item::RenameOnErrorState const error)/*{{{*/
 {
 {
    if(FileExists(DestFile))
    if(FileExists(DestFile))
@@ -1276,9 +1294,7 @@ std::string pkgAcqIndex::GetFinalFilename() const
 {
 {
    std::string FinalFile = _config->FindDir("Dir::State::lists");
    std::string FinalFile = _config->FindDir("Dir::State::lists");
    FinalFile += URItoFileName(RealURI);
    FinalFile += URItoFileName(RealURI);
-   if (_config->FindB("Acquire::GzipIndexes",false) == true)
-      FinalFile += '.' + CurrentCompressionExtension;
-   return FinalFile;
+   return GetCompressedFileName(RealURI, FinalFile, CurrentCompressionExtension);
 }
 }
 									/*}}}*/
 									/*}}}*/
 // AcqIndex::ReverifyAfterIMS - Reverify index after an ims-hit		/*{{{*/
 // AcqIndex::ReverifyAfterIMS - Reverify index after an ims-hit		/*{{{*/
@@ -1286,16 +1302,7 @@ void pkgAcqIndex::ReverifyAfterIMS()
 {
 {
    // update destfile to *not* include the compression extension when doing
    // update destfile to *not* include the compression extension when doing
    // a reverify (as its uncompressed on disk already)
    // a reverify (as its uncompressed on disk already)
-   DestFile = GetPartialFileNameFromURI(RealURI);
-
-   // do not reverify cdrom sources as apt-cdrom may rewrite the Packages
-   // file when its doing the indexcopy
-   if (RealURI.substr(0,6) == "cdrom:")
-      return;
-
-   // adjust DestFile if its compressed on disk
-   if (_config->FindB("Acquire::GzipIndexes",false) == true)
-      DestFile += '.' + CurrentCompressionExtension;
+   DestFile = GetCompressedFileName(RealURI, GetPartialFileNameFromURI(RealURI), CurrentCompressionExtension);
 
 
    // copy FinalFile into partial/ so that we check the hash again
    // copy FinalFile into partial/ so that we check the hash again
    string FinalFile = GetFinalFilename();
    string FinalFile = GetFinalFilename();

+ 25 - 10
test/integration/test-compressed-indexes

@@ -89,7 +89,8 @@ Conf testpkg (1.0 unstable [i386])' aptget install testpkg -s
 
 
 echo 'Debug::pkgAcquire::worker "true";
 echo 'Debug::pkgAcquire::worker "true";
 debug::pkgAcquire::Auth "true";
 debug::pkgAcquire::Auth "true";
-Debug::pkgAcquire::Diffs "true";' > rootdir/etc/apt/apt.conf.d/99debugconf
+Debug::pkgAcquire::Diffs "true";
+Debug::Acquire::http "true";' > rootdir/etc/apt/apt.conf.d/99debugconf
 
 
 testovermethod() {
 testovermethod() {
 	forcecompressor $2
 	forcecompressor $2
@@ -98,23 +99,28 @@ testovermethod() {
 		rm -rf rootdir/var/lib/apt/lists
 		rm -rf rootdir/var/lib/apt/lists
 		echo "Acquire::GzipIndexes \"${INDEX}\";" > rootdir/etc/apt/apt.conf.d/02compressindex
 		echo "Acquire::GzipIndexes \"${INDEX}\";" > rootdir/etc/apt/apt.conf.d/02compressindex
 		local INDCOMP
 		local INDCOMP
-		if [ "$INDEX" = 'false' ]; then
+		if [ "$INDEX" = 'false' -o "$1" = 'cdrom' ]; then
 			INDCOMP='uncompressed'
 			INDCOMP='uncompressed'
 		else
 		else
 			INDCOMP='compressed'
 			INDCOMP='compressed'
 		fi
 		fi
 
 
-		testsuccess aptget update -o Debug::Acquire::http=1
-		msgmsg "${1}: ${COMPRESSOR}: Test with $INDCOMP indexes"
+		msgmsg "${1}: ${COMPRESSOR}: Test with $INDCOMP indexes gzip=$INDEX"
+		if [ "${1}" = 'cdrom' ]; then
+			testsuccess aptcdrom add </dev/null
+		fi
+		testsuccess aptget update
 		testrun "$INDCOMP"
 		testrun "$INDCOMP"
 
 
-		testsuccess aptget update -o Acquire::Pdiffs=1 -o Debug::Acquire::http=1
-		msgmsg "${1}: ${COMPRESSOR}: Test with $INDCOMP indexes (update unchanged with pdiffs)"
-		testrun "$INDCOMP"
+		if [ "${1}" != 'cdrom' ]; then
+			testsuccess aptget update -o Acquire::Pdiffs=1
+			msgmsg "${1}: ${COMPRESSOR}: Test with $INDCOMP indexes gzip=$INDEX (update unchanged with pdiffs)"
+			testrun "$INDCOMP"
 
 
-		testsuccess aptget update -o Acquire::Pdiffs=0 -o Debug::Acquire::http=1
-		msgmsg "${1}: ${COMPRESSOR}: Test with $INDCOMP indexes (update unchanged without pdiffs)"
-		testrun "$INDCOMP"
+			testsuccess aptget update -o Acquire::Pdiffs=0
+			msgmsg "${1}: ${COMPRESSOR}: Test with $INDCOMP indexes gzip=$INDEX (update unchanged without pdiffs)"
+			testrun "$INDCOMP"
+		fi
 
 
 		rm rootdir/etc/apt/apt.conf.d/02compressindex
 		rm rootdir/etc/apt/apt.conf.d/02compressindex
 	done
 	done
@@ -143,3 +149,12 @@ test $(echo "$GOODPOLICY" | grep -e '^testpkg:' -e '^  Candidate:' -e '^  Instal
 testequal "$GOODPOLICY" aptcache policy testpkg
 testequal "$GOODPOLICY" aptcache policy testpkg
 
 
 for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testovermethod 'http' $COMPRESSOR; done
 for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testovermethod 'http' $COMPRESSOR; done
+
+changetocdrom 'Debian APT Testdisk 0.8.15'
+rm -rf rootdir/var/lib/apt/lists
+testsuccess aptcdrom add </dev/null
+GOODPOLICY="$(aptcache policy testpkg)"
+test $(echo "$GOODPOLICY" | grep -e '^testpkg:' -e '^  Candidate:' -e '^  Installed: (none)' -e '500 cdrom://' | wc -l) -eq 4 || msgdie 'policy is broken'
+testequal "$GOODPOLICY" aptcache policy testpkg
+
+for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testovermethod 'cdrom' $COMPRESSOR; done