+
+// AcqFile::pkgAcqFile - Constructor /*{{{*/
+// ---------------------------------------------------------------------
+/* The file is added to the queue */
+pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,
+ unsigned long Size,string Dsc,string ShortDesc) :
+ Item(Owner), Md5Hash(MD5)
+{
+ Retries = _config->FindI("Acquire::Retries",0);
+
+ DestFile = flNotDir(URI);
+
+ // Create the item
+ Desc.URI = URI;
+ Desc.Description = Dsc;
+ Desc.Owner = this;
+
+ // Set the short description to the archive component
+ Desc.ShortDesc = ShortDesc;
+
+ // Get the transfer sizes
+ FileSize = Size;
+ struct stat Buf;
+ if (stat(DestFile.c_str(),&Buf) == 0)
+ {
+ // Hmm, the partial file is too big, erase it
+ if ((unsigned)Buf.st_size > Size)
+ unlink(DestFile.c_str());
+ else
+ PartialSize = Buf.st_size;
+ }
+
+ QueueURI(Desc);
+}
+ /*}}}*/
+// AcqFile::Done - Item downloaded OK /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgAcqFile::Done(string Message,unsigned long Size,string MD5,
+ pkgAcquire::MethodConfig *Cnf)
+{
+ // Check the md5
+ if (Md5Hash.empty() == false && MD5.empty() == false)
+ {
+ if (Md5Hash != MD5)
+ {
+ Status = StatError;
+ ErrorText = "MD5Sum mismatch";
+ Rename(DestFile,DestFile + ".FAILED");
+ return;
+ }
+ }
+
+ Item::Done(Message,Size,MD5,Cnf);
+
+ string FileName = LookupTag(Message,"Filename");
+ if (FileName.empty() == true)
+ {
+ Status = StatError;
+ ErrorText = "Method gave a blank filename";
+ return;
+ }
+
+ Complete = true;
+
+ // The files timestamp matches
+ if (StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
+ return;
+
+ // We have to copy it into place
+ if (FileName != DestFile)
+ {
+ Local = true;
+ if (_config->FindB("Acquire::Source-Symlinks",true) == false ||
+ Cnf->Removable == true)
+ {
+ Desc.URI = "copy:" + FileName;
+ QueueURI(Desc);
+ return;
+ }
+
+ // Erase the file if it is a symlink so we can overwrite it
+ struct stat St;
+ if (lstat(DestFile.c_str(),&St) == 0)
+ {
+ if (S_ISLNK(St.st_mode) != 0)
+ unlink(DestFile.c_str());
+ }
+
+ // Symlink the file
+ if (symlink(FileName.c_str(),DestFile.c_str()) != 0)
+ {
+ ErrorText = "Link to " + DestFile + " failure ";
+ Status = StatError;
+ Complete = false;
+ }
+ }
+}
+ /*}}}*/
+// AcqFile::Failed - Failure handler /*{{{*/