r319 - in /apt-transport-debtorrent/trunk: debtorrent.cc debtorrent.h
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Tue Nov 6 21:22:52 UTC 2007
Author: camrdale-guest
Date: Tue Nov 6 21:22:52 2007
New Revision: 319
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=319
Log:
Rename the Piece-Downloaded header to Pieces-Downloaded.
Add a debug message for updating the file size.
Only update the file size to increase it.
Reset files to empty before updating the file size.
Modified:
apt-transport-debtorrent/trunk/debtorrent.cc
apt-transport-debtorrent/trunk/debtorrent.h
Modified: apt-transport-debtorrent/trunk/debtorrent.cc
URL: http://svn.debian.org/wsvn/debtorrent/apt-transport-debtorrent/trunk/debtorrent.cc?rev=319&op=diff
==============================================================================
--- apt-transport-debtorrent/trunk/debtorrent.cc (original)
+++ apt-transport-debtorrent/trunk/debtorrent.cc Tue Nov 6 21:22:52 2007
@@ -531,13 +531,13 @@
return true;
}
- // The new Piece-Downloaded header indicating how much of the file is available
- if (stringcasecmp(Tag,"Piece-Downloaded:") == 0)
+ // The new Pieces-Downloaded header indicating how much of the file is available
+ if (stringcasecmp(Tag,"Pieces-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");
+ return _error->Error("The DebTorrent client sent an invalid Pieces-Downloaded header");
if ((unsigned)StartPos > Size)
- return _error->Error("This DebTorrent client has broken Piece-Downloaded support");
+ return _error->Error("This DebTorrent client has broken Pieces-Downloaded support");
return true;
}
@@ -970,10 +970,13 @@
/* 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);
+bool HttpMethod::UpdateFileSize(FetchResult &Res, bool Started)
+{
+ // Open the file (reset to empty if not started)
+ if (Started)
+ File = new FileFd(Res.Filename, FileFd::WriteAny);
+ else
+ File = new FileFd(Res.Filename, FileFd::WriteEmpty);
if (_error->PendingError() == true)
{
delete File;
@@ -982,15 +985,22 @@
}
// Get the old size of the file
- /*
unsigned long OldSize = File->Size();
if (_error->PendingError() == true)
{
delete File;
File = 0;
return false;
- } */
-
+ }
+
+ // Don't make files smaller (it will confuse apt)
+ if (OldSize >= Res.ResumePoint)
+ {
+ delete File;
+ File = 0;
+ return true;
+ }
+
// Set the file to the new length
File->Truncate(Res.ResumePoint);
if (_error->PendingError() == true)
@@ -1009,6 +1019,15 @@
return false;
}
+ if (Debug == true)
+ {
+ char Buf[1000];
+ sprintf(Buf,"UpdateFileSize: %s was %ld, set to %ld/%ld\n",
+ Res.Filename.c_str(), OldSize, Res.ResumePoint, Res.Size);
+ string Req = Buf;
+ cerr << Req << endl;
+ }
+
return true;
}
/*}}}*/
@@ -1180,7 +1199,7 @@
case -1:
{
// Set the file to the new length
- if (UpdateFileSize(Res) == false)
+ if (UpdateFileSize(Res, Queue->IndexFile) == false)
{
Fail();
RotateDNS();
Modified: apt-transport-debtorrent/trunk/debtorrent.h
URL: http://svn.debian.org/wsvn/debtorrent/apt-transport-debtorrent/trunk/debtorrent.h?rev=319&op=diff
==============================================================================
--- apt-transport-debtorrent/trunk/debtorrent.h (original)
+++ apt-transport-debtorrent/trunk/debtorrent.h Tue Nov 6 21:22:52 2007
@@ -136,7 +136,7 @@
bool ServerDie(ServerState *Srv);
bool RearrangeQueue(ServerState *Srv);
int DealWithHeaders(FetchResult &Res,ServerState *Srv);
- bool UpdateFileSize(FetchResult &Res);
+ bool UpdateFileSize(FetchResult &Res, bool Started);
virtual bool Fetch(FetchItem *);
virtual bool Configuration(string Message);
More information about the Debtorrent-commits
mailing list