Просмотр исходного кода

fix Alt-Filename handling of file method

A silly of-by-one error in the stripping of the extension to check for
the uncompressed filename broken in an attempt to support all
compressions in commit a09f6eb8fc67cd2d836019f448f18580396185e5.

Fixing this highlights also mistakes in the handling of the Alt-Filename
in libapt which would cause apt to remove the file from the repository
(if root has the needed rights – aka the disk isn't readonly or similar)
David Kalnischkies лет назад: 10
Родитель
Сommit
e169fa4a85
3 измененных файлов с 8 добавлено и 7 удалено
  1. 4 5
      apt-pkg/acquire-item.cc
  2. 1 1
      methods/file.cc
  3. 3 1
      test/integration/test-apt-update-file

+ 4 - 5
apt-pkg/acquire-item.cc

@@ -437,7 +437,7 @@ bool pkgAcqTransactionItem::TransactionState(TransactionStates const state)
 	 } else {
 	    if(Debug == true)
 	       std::clog << "rm " << DestFile << " # " << DescURI() << std::endl;
-	    if (RemoveFile("TransactionCommit", DestFile) == false)
+	    if (RemoveFile("TransItem::TransactionCommit", DestFile) == false)
 	       return false;
 	 }
 	 break;
@@ -470,7 +470,7 @@ bool pkgAcqIndex::TransactionState(TransactionStates const state)
 	 break;
       case TransactionCommit:
 	 if (EraseFileName.empty() == false)
-	    RemoveFile("TransactionCommit", EraseFileName);
+	    RemoveFile("AcqIndex::TransactionCommit", EraseFileName);
 	 break;
    }
    return true;
@@ -2748,9 +2748,8 @@ void pkgAcqIndex::StageDownloadDone(string const &Message)
    // methods like file:// give us an alternative (uncompressed) file
    else if (Target.KeepCompressed == false && AltFilename.empty() == false)
    {
-      if (CurrentCompressionExtension != "uncompressed")
-	 DestFile.erase(DestFile.length() - (CurrentCompressionExtension.length() + 1));
       Filename = AltFilename;
+      EraseFileName.clear();
    }
    // Methods like e.g. "file:" will give us a (compressed) FileName that is
    // not the "DestFile" we set, in this case we uncompress from the local file
@@ -2780,7 +2779,7 @@ void pkgAcqIndex::StageDownloadDone(string const &Message)
       DestFile = "/dev/null";
    }
 
-   if (EraseFileName.empty())
+   if (EraseFileName.empty() && Filename != AltFilename)
       EraseFileName = Filename;
 
    // queue uri for the next stage

+ 1 - 1
methods/file.cc

@@ -98,7 +98,7 @@ bool FileMethod::Fetch(FetchItem *Itm)
    {
       if (APT::String::Endswith(File, *ext) == true)
       {
-	 std::string const unfile = File.substr(0, File.length() - ext->length() - 1);
+	 std::string const unfile = File.substr(0, File.length() - ext->length());
 	 if (stat(unfile.c_str(),&Buf) == 0)
 	 {
 	    AltRes.Size = Buf.st_size;

+ 3 - 1
test/integration/test-apt-update-file

@@ -40,7 +40,9 @@ if [ "$(id -u)" = '0' ]; then
 	exit
 fi
 chmod 555 aptarchive/dists/unstable/main/binary-all
-testsuccess aptget update
+testsuccess aptget update -o Debug::pkgAcquire::Worker=1
+cp -a rootdir/tmp/testsuccess.output rootdir/tmp/update.output
+testsuccess grep '%0aAlt-Filename:%20' rootdir/tmp/update.output
 
 # the release files aren't an IMS-hit, but the indexes are
 redatereleasefiles '+1 hour'