r375 - in /apt-transport-debtorrent/trunk: debian/changelog debtorrent.cc debtorrent.h

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Mon May 5 01:31:46 UTC 2008


Author: camrdale-guest
Date: Mon May  5 01:31:46 2008
New Revision: 375

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=375
Log:
Add a config option to make debtorrent sources local (Closes: #477383)

Modified:
    apt-transport-debtorrent/trunk/debian/changelog
    apt-transport-debtorrent/trunk/debtorrent.cc
    apt-transport-debtorrent/trunk/debtorrent.h

Modified: apt-transport-debtorrent/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/debtorrent/apt-transport-debtorrent/trunk/debian/changelog?rev=375&op=diff
==============================================================================
--- apt-transport-debtorrent/trunk/debian/changelog (original)
+++ apt-transport-debtorrent/trunk/debian/changelog Mon May  5 01:31:46 2008
@@ -1,3 +1,9 @@
+apt-transport-debtorrent (0.2.1) unstable; urgency=low
+
+  * Add a config option to make debtorrent sources local (Closes: #477383)
+
+ -- Cameron Dale <camrdale at gmail.com>  Sun, 04 May 2008 18:26:37 -0700
+
 apt-transport-debtorrent (0.2.0) unstable; urgency=low
 
   * Upgrade transport version to 0.2

Modified: apt-transport-debtorrent/trunk/debtorrent.cc
URL: http://svn.debian.org/wsvn/debtorrent/apt-transport-debtorrent/trunk/debtorrent.cc?rev=375&op=diff
==============================================================================
--- apt-transport-debtorrent/trunk/debtorrent.cc (original)
+++ apt-transport-debtorrent/trunk/debtorrent.cc Mon May  5 01:31:46 2008
@@ -72,6 +72,7 @@
 unsigned long ConnectTimeOut = 60;
 unsigned long PollTimeOut = 300;
 bool Debug = false;
+bool NoCache = false;
 
 unsigned long CircleBuf::BwReadLimit=0;
 unsigned long CircleBuf::BwTickReadData=0;
@@ -364,6 +365,7 @@
    HaveContent = false;
    time(&Date);
    Message[0] = '\0';
+   NoCacheFile[0] = '\0';
 
    do
    {
@@ -564,6 +566,14 @@
       return true;
    }
    
+   // The new NoCache-File header indicating the file's location in DebTorrent's cache      
+   if (stringcasecmp(Tag,"NoCache-File:") == 0)
+   {
+      if (sscanf(Val.c_str(),"%[^\n]",NoCacheFile) != 1)
+	 return _error->Error("The DebTorrent client sent an invalid NoCache-File header");
+      return true;
+   }
+   
    if (stringcasecmp(Tag,"Content-Length:") == 0)
    {
       if (Encoding == Closes)
@@ -674,6 +684,13 @@
       }
    /*   } */
 
+   if (NoCache == true)
+   {
+      // Send the NoCache header
+      sprintf(Buf,"If-Local-NoCache: true\r\n");
+      Req += Buf;
+   }
+
    if (Uri.User.empty() == false || Uri.Password.empty() == false)
       Req += string("Authorization: Basic ") + 
           Base64Encode(Uri.User + ":" + Uri.Password) + "\r\n";
@@ -948,6 +965,51 @@
    Res.LastModified = Srv->Date;
    Res.Size = Srv->Size;
    
+   // No Content, a local NoCache file response
+   if (Srv->Result == 204)
+   {
+      unlink(Queue->DestFile.c_str());
+      
+      if (Srv->NoCacheFile[0] != '\0')
+      {
+	 // Use the NoCache-File header for the file name
+	 Res.Filename = Srv->NoCacheFile;
+
+	 // Open the file for hashing
+	 delete File;
+	 File = new FileFd(Res.Filename,FileFd::ReadOnly);
+	 if (_error->PendingError() == true)
+	 {
+	    delete File;
+	    File = 0;
+	    return 3;
+	 }
+
+	 Hashes *Hash = new Hashes;
+   
+	 // Fill the Hash from the cached file
+	 lseek(File->Fd(),0,SEEK_SET);
+	 if (Hash->AddFD(File->Fd(),Res.Size) == false)
+	 {
+	    _error->Errno("read","Problem hashing file");
+	    delete File;
+	    File = 0;
+	    return 3;
+	 }
+
+	 // Close the file and load the hashes
+	 delete File;
+	 File = 0;
+	 Res.TakeHashes(*Hash);
+	 return 1;
+      }
+      else
+      {
+	 _error->Error("A 204 local NoCache response was received without the NoCache-File header");
+	 return 3;
+      }
+   }
+   
    // Open the file
    delete File;
    File = new FileFd(Queue->DestFile,FileFd::WriteEmpty);
@@ -1114,6 +1176,7 @@
    
    PollTimeOut = _config->FindI("Acquire::debtorrent::Timeout",PollTimeOut);
    Debug = _config->FindB("Debug::Acquire::debtorrent",false);
+   NoCache = _config->FindB("Acquire::debtorrent::NoCache",false);
    
    return true;
 }

Modified: apt-transport-debtorrent/trunk/debtorrent.h
URL: http://svn.debian.org/wsvn/debtorrent/apt-transport-debtorrent/trunk/debtorrent.h?rev=375&op=diff
==============================================================================
--- apt-transport-debtorrent/trunk/debtorrent.h (original)
+++ apt-transport-debtorrent/trunk/debtorrent.h Mon May  5 01:31:46 2008
@@ -102,6 +102,7 @@
    enum {Header, Data} State;
    bool Persistent;
    char Message[MAXLEN];
+   char NoCacheFile[MAXLEN];
    
    // This is a Persistent attribute of the server itself.
    bool Pipeline;




More information about the Debtorrent-commits mailing list