summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2011-12-17 23:53:31 +0100
committerDavid Kalnischkies <kalnischkies@gmail.com>2011-12-17 23:53:31 +0100
commit109eb1511d0cdfa4af3196105cada30bcbb77bc8 (patch)
treec07319a3ddc9a6484561d1cea918aaecade4a7e9 /methods
parent1abbc47c045770476f5f9a57c58989d13290d51b (diff)
try to avoid direct usage of .Fd() if possible and do read()s and co
on the FileFd instead
Diffstat (limited to 'methods')
-rw-r--r--methods/cdrom.cc2
-rw-r--r--methods/copy.cc2
-rw-r--r--methods/file.cc2
-rw-r--r--methods/ftp.cc2
-rw-r--r--methods/http.cc24
-rw-r--r--methods/https.cc2
-rw-r--r--methods/rsh.cc2
7 files changed, 13 insertions, 23 deletions
diff --git a/methods/cdrom.cc b/methods/cdrom.cc
index e7114b168..22d4b9164 100644
--- a/methods/cdrom.cc
+++ b/methods/cdrom.cc
@@ -268,7 +268,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
Hashes Hash;
FileFd Fd(Res.Filename, FileFd::ReadOnly);
- Hash.AddFD(Fd.Fd(), Fd.Size());
+ Hash.AddFD(Fd);
Res.TakeHashes(Hash);
URIDone(Res);
diff --git a/methods/copy.cc b/methods/copy.cc
index f8d58e479..e81d0022b 100644
--- a/methods/copy.cc
+++ b/methods/copy.cc
@@ -85,7 +85,7 @@ bool CopyMethod::Fetch(FetchItem *Itm)
Hashes Hash;
FileFd Fd(Res.Filename, FileFd::ReadOnly);
- Hash.AddFD(Fd.Fd(), Fd.Size());
+ Hash.AddFD(Fd);
Res.TakeHashes(Hash);
URIDone(Res);
diff --git a/methods/file.cc b/methods/file.cc
index 5025c996d..7ed4e6f60 100644
--- a/methods/file.cc
+++ b/methods/file.cc
@@ -83,7 +83,7 @@ bool FileMethod::Fetch(FetchItem *Itm)
Hashes Hash;
FileFd Fd(Res.Filename, FileFd::ReadOnly);
- Hash.AddFD(Fd.Fd(), Fd.Size());
+ Hash.AddFD(Fd);
Res.TakeHashes(Hash);
URIDone(Res);
return true;
diff --git a/methods/ftp.cc b/methods/ftp.cc
index 2ca0ac6f7..ad8a7b828 100644
--- a/methods/ftp.cc
+++ b/methods/ftp.cc
@@ -868,7 +868,7 @@ bool FTPConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
if (Resume != 0)
{
- if (Hash.AddFD(To.Fd(),Resume) == false)
+ if (Hash.AddFD(To,Resume) == false)
{
_error->Errno("read",_("Problem hashing file"));
return false;
diff --git a/methods/http.cc b/methods/http.cc
index 0d81c73ed..b8ed43cd2 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -1007,31 +1007,21 @@ HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
FailFile.c_str(); // Make sure we dont do a malloc in the signal handler
FailFd = File->Fd();
FailTime = Srv->Date;
-
- // Set the expected size
- if (Srv->StartPos >= 0)
- {
- Res.ResumePoint = Srv->StartPos;
- if (ftruncate(File->Fd(),Srv->StartPos) < 0)
- _error->Errno("ftruncate", _("Failed to truncate file"));
- }
-
- // Set the start point
- lseek(File->Fd(),0,SEEK_END);
delete Srv->In.Hash;
Srv->In.Hash = new Hashes;
-
- // Fill the Hash if the file is non-empty (resume)
- if (Srv->StartPos > 0)
+
+ // Set the expected size and read file for the hashes
+ if (Srv->StartPos >= 0)
{
- lseek(File->Fd(),0,SEEK_SET);
- if (Srv->In.Hash->AddFD(File->Fd(),Srv->StartPos) == false)
+ Res.ResumePoint = Srv->StartPos;
+ File->Truncate(Srv->StartPos);
+
+ if (Srv->In.Hash->AddFD(*File,Srv->StartPos) == false)
{
_error->Errno("read",_("Problem hashing file"));
return ERROR_NOT_FROM_SERVER;
}
- lseek(File->Fd(),0,SEEK_END);
}
SetNonBlock(File->Fd(),true);
diff --git a/methods/https.cc b/methods/https.cc
index 335699907..317c8a587 100644
--- a/methods/https.cc
+++ b/methods/https.cc
@@ -314,7 +314,7 @@ bool HttpsMethod::Fetch(FetchItem *Itm)
// take hashes
Hashes Hash;
FileFd Fd(Res.Filename, FileFd::ReadOnly);
- Hash.AddFD(Fd.Fd(), Fd.Size());
+ Hash.AddFD(Fd);
Res.TakeHashes(Hash);
// keep apt updated
diff --git a/methods/rsh.cc b/methods/rsh.cc
index da9777fc4..d249ae961 100644
--- a/methods/rsh.cc
+++ b/methods/rsh.cc
@@ -305,7 +305,7 @@ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long long Resume,
return false;
if (Resume != 0) {
- if (Hash.AddFD(To.Fd(),Resume) == false) {
+ if (Hash.AddFD(To,Resume) == false) {
_error->Errno("read",_("Problem hashing file"));
return false;
}