summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2012-01-05 20:20:24 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2012-01-05 20:20:24 +0100
commit570590c0640f71c98893051420517894be8eb6eb (patch)
tree563eeacf3aa349c1c7366c073cfb99348ab1c6a8 /methods
parentb7c7eb099c8d228935f9c3fa0a7c788a4018bfb1 (diff)
parent5c6ceb4557cb6497dea827d1ec4e2615ccd53e50 (diff)
merged from debian-experimental2
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/rred.cc49
-rw-r--r--methods/rsh.cc2
8 files changed, 25 insertions, 60 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/rred.cc b/methods/rred.cc
index 2a70a9f91..bf9294d96 100644
--- a/methods/rred.cc
+++ b/methods/rred.cc
@@ -37,13 +37,10 @@ class RredMethod : public pkgAcqMethod {
// return values
enum State {ED_OK, ED_ORDERING, ED_PARSER, ED_FAILURE, MMAP_FAILED};
- State applyFile(FileFd &ed_cmds, FILE *in_file, FILE *out_file,
+ State applyFile(FileFd &ed_cmds, FileFd &in_file, FileFd &out_file,
unsigned long &line, char *buffer, Hashes *hash) const;
- void ignoreLineInFile(FILE *fin, char *buffer) const;
void ignoreLineInFile(FileFd &fin, char *buffer) const;
- void copyLinesFromFileToFile(FILE *fin, FILE *fout, unsigned int lines,
- Hashes *hash, char *buffer) const;
- void copyLinesFromFileToFile(FileFd &fin, FILE *fout, unsigned int lines,
+ void copyLinesFromFileToFile(FileFd &fin, FileFd &fout, unsigned int lines,
Hashes *hash, char *buffer) const;
State patchFile(FileFd &Patch, FileFd &From, FileFd &out_file, Hashes *hash) const;
@@ -72,7 +69,7 @@ public:
* \param hash the created file for correctness
* \return the success State of the ed command executor
*/
-RredMethod::State RredMethod::applyFile(FileFd &ed_cmds, FILE *in_file, FILE *out_file,
+RredMethod::State RredMethod::applyFile(FileFd &ed_cmds, FileFd &in_file, FileFd &out_file,
unsigned long &line, char *buffer, Hashes *hash) const {
// get the current command and parse it
if (ed_cmds.ReadLine(buffer, BUF_SIZE) == NULL) {
@@ -178,39 +175,19 @@ RredMethod::State RredMethod::applyFile(FileFd &ed_cmds, FILE *in_file, FILE *ou
return ED_OK;
}
/*}}}*/
-void RredMethod::copyLinesFromFileToFile(FILE *fin, FILE *fout, unsigned int lines,/*{{{*/
- Hashes *hash, char *buffer) const {
- while (0 < lines--) {
- do {
- fgets(buffer, BUF_SIZE, fin);
- size_t const written = fwrite(buffer, 1, strlen(buffer), fout);
- hash->Add((unsigned char*)buffer, written);
- } while (strlen(buffer) == (BUF_SIZE - 1) &&
- buffer[BUF_SIZE - 2] != '\n');
- }
-}
- /*}}}*/
-void RredMethod::copyLinesFromFileToFile(FileFd &fin, FILE *fout, unsigned int lines,/*{{{*/
+void RredMethod::copyLinesFromFileToFile(FileFd &fin, FileFd &fout, unsigned int lines,/*{{{*/
Hashes *hash, char *buffer) const {
while (0 < lines--) {
do {
fin.ReadLine(buffer, BUF_SIZE);
- size_t const written = fwrite(buffer, 1, strlen(buffer), fout);
- hash->Add((unsigned char*)buffer, written);
+ unsigned long long const towrite = strlen(buffer);
+ fout.Write(buffer, towrite);
+ hash->Add((unsigned char*)buffer, towrite);
} while (strlen(buffer) == (BUF_SIZE - 1) &&
buffer[BUF_SIZE - 2] != '\n');
}
}
/*}}}*/
-void RredMethod::ignoreLineInFile(FILE *fin, char *buffer) const { /*{{{*/
- fgets(buffer, BUF_SIZE, fin);
- while (strlen(buffer) == (BUF_SIZE - 1) &&
- buffer[BUF_SIZE - 2] != '\n') {
- fgets(buffer, BUF_SIZE, fin);
- buffer[0] = ' ';
- }
-}
- /*}}}*/
void RredMethod::ignoreLineInFile(FileFd &fin, char *buffer) const { /*{{{*/
fin.ReadLine(buffer, BUF_SIZE);
while (strlen(buffer) == (BUF_SIZE - 1) &&
@@ -223,20 +200,18 @@ void RredMethod::ignoreLineInFile(FileFd &fin, char *buffer) const { /*{{{*/
RredMethod::State RredMethod::patchFile(FileFd &Patch, FileFd &From, /*{{{*/
FileFd &out_file, Hashes *hash) const {
char buffer[BUF_SIZE];
- FILE* fFrom = fdopen(From.Fd(), "r");
- FILE* fTo = fdopen(out_file.Fd(), "w");
/* we do a tail recursion to read the commands in the right order */
unsigned long line = -1; // assign highest possible value
- State const result = applyFile(Patch, fFrom, fTo, line, buffer, hash);
+ State const result = applyFile(Patch, From, out_file, line, buffer, hash);
/* read the rest from infile */
if (result == ED_OK) {
- while (fgets(buffer, BUF_SIZE, fFrom) != NULL) {
- size_t const written = fwrite(buffer, 1, strlen(buffer), fTo);
- hash->Add((unsigned char*)buffer, written);
+ while (From.ReadLine(buffer, BUF_SIZE) != NULL) {
+ unsigned long long const towrite = strlen(buffer);
+ out_file.Write(buffer, towrite);
+ hash->Add((unsigned char*)buffer, towrite);
}
- fflush(fTo);
}
return result;
}
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;
}