summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
Diffstat (limited to 'methods')
-rw-r--r--methods/bzip2.cc3
-rw-r--r--methods/cdrom.cc2
-rw-r--r--methods/gzip.cc3
-rw-r--r--methods/http.cc17
-rw-r--r--methods/https.cc6
-rw-r--r--methods/makefile12
-rw-r--r--methods/rred.cc58
7 files changed, 75 insertions, 26 deletions
diff --git a/methods/bzip2.cc b/methods/bzip2.cc
index ccc3669a2..42932dded 100644
--- a/methods/bzip2.cc
+++ b/methods/bzip2.cc
@@ -56,9 +56,8 @@ bool Bzip2Method::Fetch(FetchItem *Itm)
// Open the source and destination files
FileFd From(Path,FileFd::ReadOnly);
- // FIXME add an error message saying that empty files can't be valid archives
if(From.FileSize() == 0)
- return false;
+ return _error->Error(_("Empty files can't be valid archives"));
int GzOut[2];
if (pipe(GzOut) < 0)
diff --git a/methods/cdrom.cc b/methods/cdrom.cc
index bf4281e40..b25fdf5a8 100644
--- a/methods/cdrom.cc
+++ b/methods/cdrom.cc
@@ -220,7 +220,7 @@ bool CDROMMethod::Fetch(FetchItem *Itm)
}
bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect", true);
- CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
+ CDROM = _config->FindDir("Acquire::cdrom::mount");
if (Debug)
clog << "Looking for CDROM at " << CDROM << endl;
diff --git a/methods/gzip.cc b/methods/gzip.cc
index f1c76066e..fc4e1ecfd 100644
--- a/methods/gzip.cc
+++ b/methods/gzip.cc
@@ -48,9 +48,8 @@ bool GzipMethod::Fetch(FetchItem *Itm)
// Open the source and destination files
FileFd From(Path,FileFd::ReadOnlyGzip);
- // FIXME add an error message saying that empty files can't be valid archives
if(From.FileSize() == 0)
- return false;
+ return _error->Error(_("Empty files can't be valid archives"));
FileFd To(Itm->DestFile,FileFd::WriteAtomic);
To.EraseOnFailure();
diff --git a/methods/http.cc b/methods/http.cc
index 25e31de9a..dfc1619e3 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -1349,9 +1349,10 @@ bool HttpMethod::AutoDetectProxy()
pid_t Process = ExecFork();
if (Process == 0)
{
+ close(Pipes[0]);
dup2(Pipes[1],STDOUT_FILENO);
SetCloseExec(STDOUT_FILENO,false);
-
+
const char *Args[2];
Args[0] = AutoDetectProxyCmd.c_str();
Args[1] = 0;
@@ -1361,10 +1362,18 @@ bool HttpMethod::AutoDetectProxy()
}
char buf[512];
int InFd = Pipes[0];
- if (read(InFd, buf, sizeof(buf)) < 0)
+ close(Pipes[1]);
+ int res = read(InFd, buf, sizeof(buf));
+ ExecWait(Process, "ProxyAutoDetect", true);
+
+ if (res < 0)
return _error->Errno("read", "Failed to read");
- ExecWait(Process, "ProxyAutoDetect");
-
+ if (res == 0)
+ return _error->Warning("ProxyAutoDetect returned no data");
+
+ // add trailing \0
+ buf[res] = 0;
+
if (Debug)
clog << "auto detect command returned: '" << buf << "'" << endl;
diff --git a/methods/https.cc b/methods/https.cc
index aa6786aa8..fc649d6c2 100644
--- a/methods/https.cc
+++ b/methods/https.cc
@@ -143,13 +143,11 @@ bool HttpsMethod::Fetch(FetchItem *Itm)
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, peer_verify);
// ... and hostname against cert CN or subjectAltName
- int default_verify = 2;
bool verify = _config->FindB("Acquire::https::Verify-Host",true);
knob = "Acquire::https::"+remotehost+"::Verify-Host";
verify = _config->FindB(knob.c_str(),verify);
- if (!verify)
- default_verify = 0;
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, verify);
+ int const default_verify = (verify == true) ? 2 : 0;
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, default_verify);
// Also enforce issuer of server certificate using its cert
string issuercert = _config->Find("Acquire::https::IssuerCert","");
diff --git a/methods/makefile b/methods/makefile
index d94a85340..6ba51058e 100644
--- a/methods/makefile
+++ b/methods/makefile
@@ -67,7 +67,7 @@ include $(PROGRAM_H)
# The rred method
PROGRAM=rred
-SLIBS = -lapt-pkg $(SOCKETLIBS) $(INTLLIBS)
+SLIBS = -lapt-pkg -lz $(SOCKETLIBS) $(INTLLIBS)
LIB_MAKES = apt-pkg/makefile
SOURCE = rred.cc
include $(PROGRAM_H)
@@ -94,8 +94,8 @@ SOURCE = bzip2.cc
include $(PROGRAM_H)
# SSH and lzma method symlink
-binary: $(BIN)/ssh $(BIN)/lzma
-veryclean: clean-$(BIN)/ssh clean-$(BIN)/lzma
+binary: $(BIN)/ssh $(BIN)/lzma $(BIN)/xz
+veryclean: clean-$(BIN)/ssh clean-$(BIN)/lzma clean-$(BIN)/xz
$(BIN)/ssh:
echo "Installing ssh method link"
@@ -108,3 +108,9 @@ $(BIN)/lzma:
ln -fs bzip2 $(BIN)/lzma
clean-$(BIN)/lzma:
-rm $(BIN)/lzma
+
+$(BIN)/xz:
+ echo "Installing xz method link"
+ ln -fs bzip2 $(BIN)/xz
+clean-$(BIN)/xz:
+ -rm $(BIN)/xz
diff --git a/methods/rred.cc b/methods/rred.cc
index d51c45c85..849973e1a 100644
--- a/methods/rred.cc
+++ b/methods/rred.cc
@@ -12,6 +12,7 @@
#include <utime.h>
#include <stdio.h>
#include <errno.h>
+#include <zlib.h>
#include <apti18n.h>
/*}}}*/
/** \brief RredMethod - ed-style incremential patch method {{{
@@ -33,11 +34,14 @@ class RredMethod : public pkgAcqMethod {
// return values
enum State {ED_OK, ED_ORDERING, ED_PARSER, ED_FAILURE, MMAP_FAILED};
- State applyFile(FILE *ed_cmds, FILE *in_file, FILE *out_file,
+ State applyFile(gzFile &ed_cmds, FILE *in_file, FILE *out_file,
unsigned long &line, char *buffer, Hashes *hash) const;
void ignoreLineInFile(FILE *fin, char *buffer) const;
+ void ignoreLineInFile(gzFile &fin, char *buffer) const;
void copyLinesFromFileToFile(FILE *fin, FILE *fout, unsigned int lines,
Hashes *hash, char *buffer) const;
+ void copyLinesFromFileToFile(gzFile &fin, FILE *fout, unsigned int lines,
+ Hashes *hash, char *buffer) const;
State patchFile(FileFd &Patch, FileFd &From, FileFd &out_file, Hashes *hash) const;
State patchMMap(FileFd &Patch, FileFd &From, FileFd &out_file, Hashes *hash) const;
@@ -65,10 +69,10 @@ public:
* \param hash the created file for correctness
* \return the success State of the ed command executor
*/
-RredMethod::State RredMethod::applyFile(FILE *ed_cmds, FILE *in_file, FILE *out_file,
+RredMethod::State RredMethod::applyFile(gzFile &ed_cmds, FILE *in_file, FILE *out_file,
unsigned long &line, char *buffer, Hashes *hash) const {
// get the current command and parse it
- if (fgets(buffer, BUF_SIZE, ed_cmds) == NULL) {
+ if (gzgets(ed_cmds, buffer, BUF_SIZE) == NULL) {
if (Debug == true)
std::clog << "rred: encounter end of file - we can start patching now." << std::endl;
line = 0;
@@ -123,7 +127,7 @@ RredMethod::State RredMethod::applyFile(FILE *ed_cmds, FILE *in_file, FILE *out_
unsigned char mode = *idx;
// save the current position
- unsigned const long pos = ftell(ed_cmds);
+ unsigned const long pos = gztell(ed_cmds);
// if this is add or change then go to the next full stop
unsigned int data_length = 0;
@@ -157,7 +161,7 @@ RredMethod::State RredMethod::applyFile(FILE *ed_cmds, FILE *in_file, FILE *out_
// include data from ed script
if (mode == MODE_CHANGED || mode == MODE_ADDED) {
- fseek(ed_cmds, pos, SEEK_SET);
+ gzseek(ed_cmds, pos, SEEK_SET);
copyLinesFromFileToFile(ed_cmds, out_file, data_length, hash, buffer);
}
@@ -183,6 +187,18 @@ void RredMethod::copyLinesFromFileToFile(FILE *fin, FILE *fout, unsigned int lin
}
}
/*}}}*/
+void RredMethod::copyLinesFromFileToFile(gzFile &fin, FILE *fout, unsigned int lines,/*{{{*/
+ Hashes *hash, char *buffer) const {
+ while (0 < lines--) {
+ do {
+ gzgets(fin, buffer, BUF_SIZE);
+ 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::ignoreLineInFile(FILE *fin, char *buffer) const { /*{{{*/
fgets(buffer, BUF_SIZE, fin);
while (strlen(buffer) == (BUF_SIZE - 1) &&
@@ -192,11 +208,20 @@ void RredMethod::ignoreLineInFile(FILE *fin, char *buffer) const { /*{{{*/
}
}
/*}}}*/
+void RredMethod::ignoreLineInFile(gzFile &fin, char *buffer) const { /*{{{*/
+ gzgets(fin, buffer, BUF_SIZE);
+ while (strlen(buffer) == (BUF_SIZE - 1) &&
+ buffer[BUF_SIZE - 2] != '\n') {
+ gzgets(fin, buffer, BUF_SIZE);
+ buffer[0] = ' ';
+ }
+}
+ /*}}}*/
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* fPatch = fdopen(Patch.Fd(), "r");
+ gzFile fPatch = Patch.gzFd();
FILE* fTo = fdopen(out_file.Fd(), "w");
/* we do a tail recursion to read the commands in the right order */
@@ -227,7 +252,20 @@ struct EdCommand { /*{{{*/
RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From, /*{{{*/
FileFd &out_file, Hashes *hash) const {
#ifdef _POSIX_MAPPED_FILES
- MMap ed_cmds(Patch, MMap::ReadOnly);
+ MMap ed_cmds(MMap::ReadOnly);
+ if (Patch.gzFd() != NULL) {
+ unsigned long mapSize = Patch.Size();
+ DynamicMMap* dyn = new DynamicMMap(0, mapSize, 0);
+ if (dyn->validData() == false) {
+ delete dyn;
+ return MMAP_FAILED;
+ }
+ dyn->AddSize(mapSize);
+ gzread(Patch.gzFd(), dyn->Data(), mapSize);
+ ed_cmds = *dyn;
+ } else
+ ed_cmds = MMap(Patch, MMap::ReadOnly);
+
MMap in_file(From, MMap::ReadOnly);
if (ed_cmds.Size() == 0 || in_file.Size() == 0)
@@ -445,7 +483,7 @@ bool RredMethod::Fetch(FetchItem *Itm) /*{{{*/
// Open the source and destination files (the d'tor of FileFd will do
// the cleanup/closing of the fds)
FileFd From(Path,FileFd::ReadOnly);
- FileFd Patch(Path+".ed",FileFd::ReadOnly);
+ FileFd Patch(Path+".ed",FileFd::ReadOnlyGzip);
FileFd To(Itm->DestFile,FileFd::WriteAtomic);
To.EraseOnFailure();
if (_error->PendingError() == true)
@@ -456,8 +494,8 @@ bool RredMethod::Fetch(FetchItem *Itm) /*{{{*/
State const result = patchMMap(Patch, From, To, &Hash);
if (result == MMAP_FAILED) {
// retry with patchFile
- lseek(Patch.Fd(), 0, SEEK_SET);
- lseek(From.Fd(), 0, SEEK_SET);
+ Patch.Seek(0);
+ From.Seek(0);
To.Open(Itm->DestFile,FileFd::WriteAtomic);
if (_error->PendingError() == true)
return false;