From e62aa1dd8099aeb8bb667253ca22c56b93f521d1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 29 Jan 2014 23:02:51 +0100 Subject: pkgTagFile: if we have seen the end, do not try to see more Asking for more via Step() will notice that we are done with the file already and will result in a fail, which means we can't find the last sections anymore (which is especially painful if we haven't moved at all as in the testcase we haven't even looked at one of the sources leading to a strange behaviour) Reported-By: Niall Walsh --- apt-pkg/tagfile.cc | 6 ++++- test/integration/test-apt-get-source-multisources | 30 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 test/integration/test-apt-get-source-multisources diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index b92b2c15a..832a40d1e 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -207,7 +207,11 @@ bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long long Offset) unsigned long long Dist = Offset - d->iOffset; d->Start += Dist; d->iOffset += Dist; - return Step(Tag); + // if we have seen the end, don't ask for more + if (d->Done == true) + return Tag.Scan(d->Start, d->End - d->Start); + else + return Step(Tag); } // Reposition and reload.. diff --git a/test/integration/test-apt-get-source-multisources b/test/integration/test-apt-get-source-multisources new file mode 100755 index 000000000..cc759e8c1 --- /dev/null +++ b/test/integration/test-apt-get-source-multisources @@ -0,0 +1,30 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +setupenvironment +configarchitecture 'armhf' + +insertsource 'unstable' 'adduser' 'all' '3.113+nmu3' +insertsource 'stable' 'python-fll' 'all' '0.9.11' + +insertpackage 'unstable' 'adduser' 'all' '3.113+nmu3' +insertpackage 'stable' 'python-fll' 'all' '0.9.11' + +setupaptarchive + +APTARCHIVE=$(readlink -f ./aptarchive) + +HEADER="Reading package lists... +Building dependency tree..." +testequal "$HEADER +Need to get 0 B of source archives. +'file://${APTARCHIVE}/adduser_3.113+nmu3.dsc' adduser_3.113+nmu3.dsc 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e +'file://${APTARCHIVE}/python-fll_0.9.11.dsc' python-fll_0.9.11.dsc 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e" aptget source -qdy --print-uris --dsc-only adduser=3.113 python-fll=0.9.11 + +testequal "$HEADER +Need to get 0 B of source archives. +'file://${APTARCHIVE}/python-fll_0.9.11.dsc' python-fll_0.9.11.dsc 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e +'file://${APTARCHIVE}/adduser_3.113+nmu3.dsc' adduser_3.113+nmu3.dsc 0 MD5Sum:d41d8cd98f00b204e9800998ecf8427e" aptget source -qdy --print-uris --dsc-only python-fll=0.9.11 adduser=3.113 -- cgit v1.2.3 From 6a9c9d63edc878ff268cdaa4f985ca50c48380b0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 29 Jan 2014 23:24:41 +0100 Subject: restart debSrcRecordParsers only if needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The offset variable in DebSrcRecordParser was not initialized which we now do and based on it do not trigger a restart if the parser was not used yet avoiding a needless rescan of the section. Detected while working on the previous commit e62aa1dd. Both commits act as a "fix" for the bug shown in the testcase of the commit – this one here would only hide it through. --- apt-pkg/deb/debsrcrecords.h | 6 +++--- apt-pkg/srcrecords.cc | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h index 5d2a67f4f..a8fb465bb 100644 --- a/apt-pkg/deb/debsrcrecords.h +++ b/apt-pkg/deb/debsrcrecords.h @@ -30,7 +30,7 @@ class debSrcRecordParser : public pkgSrcRecords::Parser public: - virtual bool Restart() {return Tags.Jump(Sect,0);}; + virtual bool Restart() {return Jump(0);}; virtual bool Step() {iOffset = Tags.Offset(); return Tags.Step(Sect);}; virtual bool Jump(unsigned long const &Off) {iOffset = Off; return Tags.Jump(Sect,Off);}; @@ -50,8 +50,8 @@ class debSrcRecordParser : public pkgSrcRecords::Parser virtual bool Files(std::vector &F); debSrcRecordParser(std::string const &File,pkgIndexFile const *Index) - : Parser(Index), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400), - Buffer(NULL) {} + : Parser(Index), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400), + iOffset(0), Buffer(NULL) {} virtual ~debSrcRecordParser(); }; diff --git a/apt-pkg/srcrecords.cc b/apt-pkg/srcrecords.cc index 297559957..60b62850a 100644 --- a/apt-pkg/srcrecords.cc +++ b/apt-pkg/srcrecords.cc @@ -70,8 +70,9 @@ bool pkgSrcRecords::Restart() Current = Files.begin(); for (std::vector::iterator I = Files.begin(); I != Files.end(); ++I) - (*I)->Restart(); - + if ((*I)->Offset() != 0) + (*I)->Restart(); + return true; } /*}}}*/ -- cgit v1.2.3 From 25d99f3b42ada24679ddc1d911530425acc8e475 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 30 Jan 2014 00:11:05 +0100 Subject: fix various style/performance warnings in rred Reported-By: cppcheck Git-Dch: Ignore --- methods/gpgv.cc | 1 - methods/http.cc | 1 - methods/rred.cc | 67 +++++++++++++++++++++------------------------------------ 3 files changed, 24 insertions(+), 45 deletions(-) diff --git a/methods/gpgv.cc b/methods/gpgv.cc index ea8a26fd4..25bf64ddd 100644 --- a/methods/gpgv.cc +++ b/methods/gpgv.cc @@ -8,7 +8,6 @@ #include #include -#include #include #include #include diff --git a/methods/http.cc b/methods/http.cc index e1390afcb..96c4e3ca0 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -36,7 +36,6 @@ #include #include -#include #include #include #include diff --git a/methods/rred.cc b/methods/rred.cc index d17ab110d..f7dac3c19 100644 --- a/methods/rred.cc +++ b/methods/rred.cc @@ -20,12 +20,12 @@ #include #include +#include #include #include #include #include #include -#include #include @@ -37,11 +37,9 @@ class MemBlock { char *free; struct MemBlock *next; - MemBlock(size_t size) + MemBlock(size_t size) : size(size), next(NULL) { free = start = new char[size]; - size = size; - next = NULL; } size_t avail(void) { return size - (free - start); } @@ -157,7 +155,7 @@ class FileChanges { #ifdef POSDEBUG size_t cpos = 0; std::list::iterator x; - for (x = changes.begin(); x != where; x++) { + for (x = changes.begin(); x != where; ++x) { assert(x != changes.end()); cpos += x->offset + x->add_cnt; } @@ -208,7 +206,7 @@ class FileChanges { left(); } std::list::iterator next = where; - next++; + ++next; while (next != changes.end() && next->offset == 0) { where->del_cnt += next->del_cnt; @@ -221,7 +219,7 @@ class FileChanges { where->add_cnt = next->add_cnt; next = changes.erase(next); } else { - next++; + ++next; } } } @@ -261,7 +259,7 @@ class FileChanges { if (where != changes.end()) where->offset -= offset; changes.insert(where, Change(offset)); - where--; + --where; assert(pos_is_okay()); } @@ -284,26 +282,10 @@ class FileChanges { before.add_len -= where->add_len; changes.insert(where, before); - where--; + --where; assert(pos_is_okay()); } - size_t check_next_offset(size_t max) - { - assert(pos_is_okay()); - if (max > 0) - { - where++; - if (where != changes.end()) { - if (where->offset < max) - max = where->offset; - } - where--; - assert(pos_is_okay()); - } - return max; - } - void delete_lines(size_t cnt) { std::list::iterator x = where; @@ -317,7 +299,7 @@ class FileChanges { x->skip_lines(del); cnt -= del; - x++; + ++x; if (x == changes.end()) { del = cnt; } else { @@ -334,7 +316,7 @@ class FileChanges { void left(void) { assert(pos_is_okay()); - where--; + --where; pos -= where->offset + where->add_cnt; assert(pos_is_okay()); } @@ -342,7 +324,7 @@ class FileChanges { void right(void) { assert(pos_is_okay()); pos += where->offset + where->add_cnt; - where++; + ++where; assert(pos_is_okay()); } }; @@ -378,11 +360,10 @@ class Patch { static void dump_lines(FILE *o, FILE *i, size_t n, Hashes *hash) { char buffer[BLOCK_SIZE]; - size_t l; while (n > 0) { if (fgets(buffer, sizeof(buffer), i) == 0) buffer[0] = '\0'; - l = strlen(buffer); + size_t const l = strlen(buffer); if (l == 0 || buffer[l-1] == '\n') n--; retry_fwrite(buffer, l, o, hash); @@ -392,11 +373,10 @@ class Patch { static void skip_lines(FILE *i, int n) { char buffer[BLOCK_SIZE]; - size_t l; while (n > 0) { if (fgets(buffer, sizeof(buffer), i) == 0) buffer[0] = '\0'; - l = strlen(buffer); + size_t const l = strlen(buffer); if (l == 0 || buffer[l-1] == '\n') n--; } @@ -490,14 +470,14 @@ class Patch { { size_t line = 0; std::list::reverse_iterator ch; - for (ch = filechanges.rbegin(); ch != filechanges.rend(); ch++) { + for (ch = filechanges.rbegin(); ch != filechanges.rend(); ++ch) { line += ch->offset + ch->del_cnt; } - for (ch = filechanges.rbegin(); ch != filechanges.rend(); ch++) { + for (ch = filechanges.rbegin(); ch != filechanges.rend(); ++ch) { std::list::reverse_iterator mg_i, mg_e = ch; while (ch->del_cnt == 0 && ch->offset == 0) - ch++; + ++ch; line -= ch->del_cnt; if (ch->add_cnt > 0) { if (ch->del_cnt == 0) { @@ -526,7 +506,7 @@ class Patch { void apply_against_file(FILE *out, FILE *in, Hashes *hash = NULL) { std::list::iterator ch; - for (ch = filechanges.begin(); ch != filechanges.end(); ch++) { + for (ch = filechanges.begin(); ch != filechanges.end(); ++ch) { dump_lines(out, in, ch->offset, hash); skip_lines(in, ch->del_cnt); dump_mem(out, ch->add, ch->add_len, hash); @@ -575,7 +555,7 @@ class RredMethod : public pkgAcqMethod { std::string patch_name; for (std::vector::iterator I = patchpaths.begin(); I != patchpaths.end(); - I++) + ++I) { patch_name = *I; if (Debug == true) @@ -617,11 +597,12 @@ class RredMethod : public pkgAcqMethod { stat(patch_name.c_str(), &bufpatch) != 0) return _error->Errno("stat", _("Failed to stat")); - struct utimbuf timebuf; - timebuf.actime = bufbase.st_atime; - timebuf.modtime = bufpatch.st_mtime; - if (utime(Itm->DestFile.c_str(), &timebuf) != 0) - return _error->Errno("utime", _("Failed to set modification time")); + struct timespec times[2]; + times[0].tv_sec = bufbase.st_atime; + times[1].tv_sec = bufpatch.st_mtime; + times[0].tv_nsec = times[1].tv_nsec = 0; + if (utimensat(AT_FDCWD, Itm->DestFile.c_str(), times, 0) != 0) + return _error->Errno("utimensat",_("Failed to set modification time")); if (stat(Itm->DestFile.c_str(), &bufbase) != 0) return _error->Errno("stat", _("Failed to stat")); @@ -635,7 +616,7 @@ class RredMethod : public pkgAcqMethod { } public: - RredMethod() : pkgAcqMethod("2.0",SingleInstance | SendConfig) {} + RredMethod() : pkgAcqMethod("2.0",SingleInstance | SendConfig), Debug(false) {} }; int main(int argc, char **argv) -- cgit v1.2.3