Parcourir la source

don't try other compressions on hashsum mismatch

If we e.g. fail on hash verification for Packages.xz its highly unlikely
that it will be any better with Packages.gz, so we just waste download
bandwidth and time. It also causes us always to fallback to the
uncompressed Packages file for which the error will finally be reported,
which in turn confuses users as the file usually doesn't exist on the
mirrors, so a bug in apt is suspected for even trying it…
David Kalnischkies il y a 11 ans
Parent
commit
58702f8563

+ 23 - 10
apt-pkg/acquire-item.cc

@@ -154,7 +154,18 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
 	 return;
 	 return;
       }
       }
 
 
-      Status = StatError;
+      switch (Status)
+      {
+	 case StatIdle:
+	 case StatFetching:
+	 case StatDone:
+	    Status = StatError;
+	    break;
+	 case StatAuthError:
+	 case StatError:
+	 case StatTransientNetworkError:
+	    break;
+      }
       Complete = false;
       Complete = false;
       Dequeue();
       Dequeue();
    }
    }
@@ -167,7 +178,7 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
       RenameOnError(MaximumSizeExceeded);
       RenameOnError(MaximumSizeExceeded);
 
 
    // report mirror failure back to LP if we actually use a mirror
    // report mirror failure back to LP if we actually use a mirror
-   if(FailReason.size() != 0)
+   if(FailReason.empty() == false)
       ReportMirrorFailure(FailReason);
       ReportMirrorFailure(FailReason);
    else
    else
       ReportMirrorFailure(ErrorText);
       ReportMirrorFailure(ErrorText);
@@ -1403,17 +1414,19 @@ void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
 {
 {
    Item::Failed(Message,Cnf);
    Item::Failed(Message,Cnf);
 
 
-   size_t const nextExt = CompressionExtensions.find(' ');
-   if (nextExt != std::string::npos)
+   // authorisation matches will not be fixed by other compression types
+   if (Status != StatAuthError)
    {
    {
-      CompressionExtensions = CompressionExtensions.substr(nextExt+1);
-      Init(RealURI, Desc.Description, Desc.ShortDesc);
-      Status = StatIdle;
-      return;
+      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;
+      }
    }
    }
 
 
-   Item::Failed(Message,Cnf);
-
    if(Target->IsOptional() && ExpectedHashes.empty() && Stage == STAGE_DOWNLOAD)
    if(Target->IsOptional() && ExpectedHashes.empty() && Stage == STAGE_DOWNLOAD)
       Status = StatDone;
       Status = StatDone;
    else
    else

+ 21 - 2
test/integration/test-apt-update-not-modified

@@ -14,6 +14,7 @@ setupaptarchive --no-update
 methodtest() {
 methodtest() {
 	msgmsg 'Test InRelease with' "$1"
 	msgmsg 'Test InRelease with' "$1"
 	rm -rf rootdir/var/lib/apt/lists
 	rm -rf rootdir/var/lib/apt/lists
+	cp -a aptarchive/dists  aptarchive/dists.good
 	# get our cache populated
 	# get our cache populated
 	testsuccess aptget update
 	testsuccess aptget update
 	listcurrentlistsdirectory > listsdir.lst
 	listcurrentlistsdirectory > listsdir.lst
@@ -30,8 +31,27 @@ Reading package lists..." aptget update
 Reading package lists..." aptget update
 Reading package lists..." aptget update
 	testfileequal 'listsdir-without-amd64.lst' "$(listcurrentlistsdirectory)"
 	testfileequal 'listsdir-without-amd64.lst' "$(listcurrentlistsdirectory)"
 
 
-	# readd arch so its downloaded again
+	# readd arch so its downloaded again
 	configarchitecture 'amd64' 'i386'
 	configarchitecture 'amd64' 'i386'
+	# … but oh noes, hashsum mismatch!
+	find aptarchive/dists/unstable/main/binary-amd64/ -type f -delete
+	cat >> aptarchive/dists/unstable/main/binary-amd64/Packages <<EOF
+
+Package: thisisbad
+Architecture: amd64
+Version: 1
+EOF
+	compressfile aptarchive/dists/unstable/main/binary-amd64/Packages
+	testfailureequal "Hit $1 unstable InRelease
+Get:1 $1 unstable/main amd64 Packages [$(stat -c '%s' 'aptarchive/dists.good/unstable/main/binary-amd64/Packages.gz') B]
+W: Failed to fetch $1/dists/unstable/main/binary-amd64/Packages.gz  Hash Sum mismatch
+
+E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
+	testfileequal 'listsdir-without-amd64.lst' "$(listcurrentlistsdirectory)"
+	rm -rf aptarchive/dists
+	cp -a aptarchive/dists.good aptarchive/dists
+
+	# … now everything is fine again
 	testsuccessequal "Hit $1 unstable InRelease
 	testsuccessequal "Hit $1 unstable InRelease
 Get:1 $1 unstable/main amd64 Packages [$(stat -c '%s' 'aptarchive/dists/unstable/main/binary-amd64/Packages.gz') B]
 Get:1 $1 unstable/main amd64 Packages [$(stat -c '%s' 'aptarchive/dists/unstable/main/binary-amd64/Packages.gz') B]
 Reading package lists..." aptget update
 Reading package lists..." aptget update
@@ -46,7 +66,6 @@ Reading package lists..." aptget update
 
 
 	msgmsg 'Test Release.gpg with' "$1"
 	msgmsg 'Test Release.gpg with' "$1"
 	rm -rf rootdir/var/lib/apt/lists
 	rm -rf rootdir/var/lib/apt/lists
-	cp -a aptarchive/dists  aptarchive/dists.good
 	find aptarchive/dists -name 'InRelease' -delete
 	find aptarchive/dists -name 'InRelease' -delete
 	# get our cache populated
 	# get our cache populated
 	testsuccess aptget update
 	testsuccess aptget update

+ 2 - 2
test/integration/test-apt-update-rollback

@@ -60,7 +60,7 @@ test_inrelease_to_broken_hash_reverts_all() {
     break_repository_sources_index '+1hour'
     break_repository_sources_index '+1hour'
 
 
     # test the error condition
     # test the error condition
-    testfailureequal "W: Failed to fetch file:${APTARCHIVE}/dists/unstable/main/source/Sources  Hash Sum mismatch
+    testfailureequal "W: Failed to fetch file:${APTARCHIVE}/dists/unstable/main/source/Sources.gz  Hash Sum mismatch
 
 
 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
     # ensure that the Packages file is also rolled back
     # ensure that the Packages file is also rolled back
@@ -127,7 +127,7 @@ E: There are problems and -y was used without --force-yes" aptget install -qq -y
     add_new_package '+1hour'
     add_new_package '+1hour'
     break_repository_sources_index '+1hour'
     break_repository_sources_index '+1hour'
 
 
-    testfailureequal "W: Failed to fetch file:$APTARCHIVE/dists/unstable/main/source/Sources  Hash Sum mismatch
+    testfailureequal "W: Failed to fetch file:$APTARCHIVE/dists/unstable/main/source/Sources.gz  Hash Sum mismatch
 
 
 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
 E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
 
 

+ 6 - 2
test/integration/test-apt-update-transactions

@@ -8,6 +8,7 @@ TESTDIR=$(readlink -f $(dirname $0))
 
 
 setupenvironment
 setupenvironment
 configarchitecture 'i386'
 configarchitecture 'i386'
+configcompression '.' 'gz'
 
 
 insertpackage 'unstable' 'foo' 'all' '1.0'
 insertpackage 'unstable' 'foo' 'all' '1.0'
 insertsource 'unstable' 'foo' 'all' '1.0'
 insertsource 'unstable' 'foo' 'all' '1.0'
@@ -15,7 +16,8 @@ insertsource 'unstable' 'foo' 'all' '1.0'
 setupaptarchive --no-update
 setupaptarchive --no-update
 
 
 breakfile() {
 breakfile() {
-	mv "$1" "${1}.bak"
+	mv "${1}" "${1}.bak"
+	mv "${1}.gz" "${1}.gz.bak"
 	cat > "$1" <<EOF
 	cat > "$1" <<EOF
 Package: bar
 Package: bar
 EOF
 EOF
@@ -23,6 +25,7 @@ EOF
 }
 }
 restorefile() {
 restorefile() {
 	mv "${1}.bak" "$1"
 	mv "${1}.bak" "$1"
+	mv "${1}.gz.bak" "${1}.gz"
 }
 }
 
 
 testrun() {
 testrun() {
@@ -54,7 +57,8 @@ testsetup() {
 	testrun 'listsdir.lst'
 	testrun 'listsdir.lst'
 
 
 	msgmsg 'Test with initial data over' "$1"
 	msgmsg 'Test with initial data over' "$1"
-	testsuccess aptget update
+	rm -rf rootdir/var/lib/apt/lists
+	testsuccess aptget update -o Debug::pkgAcquire::Worker=1
 	listcurrentlistsdirectory > listsdir.lst
 	listcurrentlistsdirectory > listsdir.lst
 	redatereleasefiles '+1hour'
 	redatereleasefiles '+1hour'
 	testrun 'listsdir.lst'
 	testrun 'listsdir.lst'