r313 - in /apt-transport-debtorrent/trunk: debian/changelog debtorrent.cc
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Mon Nov 5 02:33:15 UTC 2007
Author: camrdale-guest
Date: Mon Nov 5 02:33:15 2007
New Revision: 313
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=313
Log:
- Create sparse files based on status messages (102) from DebTorrent
Modified:
apt-transport-debtorrent/trunk/debian/changelog
apt-transport-debtorrent/trunk/debtorrent.cc
Modified: apt-transport-debtorrent/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/debtorrent/apt-transport-debtorrent/trunk/debian/changelog?rev=313&op=diff
==============================================================================
--- apt-transport-debtorrent/trunk/debian/changelog (original)
+++ apt-transport-debtorrent/trunk/debian/changelog Mon Nov 5 02:33:15 2007
@@ -1,10 +1,11 @@
apt-transport-debtorrent (0.2.0) unstable; urgency=low
* Upgrade transport version to 0.2
+ - Create sparse files based on status messages (102) from DebTorrent
* Remove support for Range headers as they may confuse the
sparse file allocation
- -- Cameron Dale <camrdale at gmail.com> Sun, 04 Nov 2007 10:57:37 -0800
+ -- Cameron Dale <camrdale at gmail.com> Sun, 04 Nov 2007 18:31:48 -0800
apt-transport-debtorrent (0.1.1) unstable; urgency=low
Modified: apt-transport-debtorrent/trunk/debtorrent.cc
URL: http://svn.debian.org/wsvn/debtorrent/apt-transport-debtorrent/trunk/debtorrent.cc?rev=313&op=diff
==============================================================================
--- apt-transport-debtorrent/trunk/debtorrent.cc (original)
+++ apt-transport-debtorrent/trunk/debtorrent.cc Mon Nov 5 02:33:15 2007
@@ -530,7 +530,17 @@
return true;
}
-
+
+ // The new Piece-Downloaded header indicating how much of the file is available
+ if (stringcasecmp(Tag,"Piece-Downloaded:") == 0)
+ {
+ if (sscanf(Val.c_str(),"bytes %lu/%lu",&StartPos,&Size) != 2)
+ return _error->Error("The DebTorrent client sent an invalid Piece-Downloaded header");
+ if ((unsigned)StartPos > Size)
+ return _error->Error("This DebTorrent client has broken Piece-Downloaded support"); */
+ return true;
+ }
+
if (stringcasecmp(Tag,"Content-Length:") == 0)
{
if (Encoding == Closes)
@@ -875,6 +885,7 @@
// ---------------------------------------------------------------------
/* We look at the header data we got back from the server and decide what
to do. Returns
+ -1 - Piece downloaded update
0 - File is open,
1 - IMS hit
3 - Unrecoverable error
@@ -882,6 +893,15 @@
5 - Unrecoverable non-server error (close the connection) */
int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
{
+ // Piece Downloaded update message
+ if (Srv->Result == 102)
+ {
+ // Hack: use ResumePoint to temporarily store the current size
+ Res.Size = Srv->Size;
+ Res.ResumePoint = Srv->StartPos;
+ return -1;
+ }
+
// Not Modified
if (Srv->Result == 304)
{
@@ -907,7 +927,7 @@
// Open the file
delete File;
- File = new FileFd(Queue->DestFile,FileFd::WriteAny);
+ File = new FileFd(Queue->DestFile,FileFd::WriteEmpty);
if (_error->PendingError() == true)
return 5;
@@ -943,6 +963,43 @@
SetNonBlock(File->Fd(),true);
return 0;
+}
+ /*}}}*/
+// HttpMethod::UpdateFileSize - Update the output file's size /*{{{*/
+// ---------------------------------------------------------------------
+/* Increase the output file's size (sparsely) to indicate the current
+ amount of the file that has been downloaded by DebTorrent. Returns
+ false if an error occurred. */
+bool HttpMethod::UpdateFileSize(FetchResult &Res)
+{
+ // Open the file
+ File = new FileFd(Res.Filename, FileFd::WriteAny);
+ if (_error->PendingError() == true)
+ {
+ delete File;
+ File = 0;
+ return false;
+ }
+
+ // Get the old size of the file
+ unsigned long OldSize = File->Size();
+ if (_error->PendingError() == true)
+ {
+ delete File;
+ File = 0;
+ return false;
+ }
+
+ // Set the file to the new length
+ File->Truncate(Res.ResumePoint);
+ delete File;
+ File = 0;
+ if (_error->PendingError() == true)
+ {
+ return false;
+ }
+
+ return true;
}
/*}}}*/
// HttpMethod::SigTerm - Handle a fatal signal /*{{{*/
@@ -983,6 +1040,10 @@
if (QueueBack == I)
{
QueueBack = I->Next;
+
+ // Initialize the unstarted flag
+ I->IndexFile = false;
+
SendReq(I,Server->Out);
continue;
}
@@ -1105,11 +1166,33 @@
Res.Filename = Queue->DestFile;
switch (DealWithHeaders(Res,Server))
{
+ // Got an informational file size message
+ case -1:
+ {
+ // Set the file to the new length
+ if (UpdateFileSize(Res) == false)
+ {
+ Fail();
+ RotateDNS();
+ Server->Close();
+ }
+ // Hack: use the IndexFile flag to indicate if it's been started
+ else if (Queue->IndexFile == false)
+ {
+ // Make sure to unset the ResumePoint for the call to URIStart
+ Res.ResumePoint = 0;
+
+ URIStart(Res);
+
+ Queue->IndexFile = true;
+ }
+
+ break;
+ }
+
// Ok, the file is Open
case 0:
{
- URIStart(Res);
-
// Run the data
bool Result = Server->RunData();
More information about the Debtorrent-commits
mailing list