diff --git a/AUTHORS b/AUTHORS index 84d6fd11..d8e8ad09 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,3 +3,4 @@ List of contributors, in chronological order: * Andrey Smirnov (https://github.com/smira) * Sebastien Binet (https://github.com/sbinet) * Ryan Uber (https://github.com/ryanuber) +* Simon Aquino (https://github.com/simonaquino) \ No newline at end of file diff --git a/Makefile b/Makefile index df3f35a9..4be0b733 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ install: $(GOM) build -o $(BINPATH)/aptly system-test: install -ifeq ($(GOVERSION),$(filter $(GOVERSION),go1.2 go1.2.1 devel)) +ifeq ($(GOVERSION),$(filter $(GOVERSION),go1.2 go1.2.1 go1.3 devel)) if [ ! -e ~/aptly-fixture-db ]; then git clone https://github.com/aptly-dev/aptly-fixture-db.git ~/aptly-fixture-db/; fi endif if [ ! -e ~/aptly-fixture-pool ]; then git clone https://github.com/aptly-dev/aptly-fixture-pool.git ~/aptly-fixture-pool/; fi @@ -77,9 +77,7 @@ src-package: mkdir -p aptly-$(VERSION)/src/github.com/smira/aptly/ cd aptly-$(VERSION)/src/github.com/smira/ && git clone https://github.com/smira/aptly && cd aptly && git checkout v$(VERSION) cd aptly-$(VERSION)/src/github.com/smira/aptly && gom -production install - cd aptly-$(VERSION)/src/github.com/smira/aptly && find . -name .git -print | xargs rm -rf - cd aptly-$(VERSION)/src/github.com/smira/aptly && find . -name .bzr -print | xargs rm -rf - cd aptly-$(VERSION)/src/github.com/smira/aptly && find . -name .hg -print | xargs rm -rf + cd aptly-$(VERSION)/src/github.com/smira/aptly && find . \( -name .git -o -name .bzr -o -name .hg \) -print | xargs rm -rf rm -rf aptly-$(VERSION)/src/github.com/smira/aptly/_vendor/{pkg,bin} tar cyf aptly-$(VERSION)-src.tar.bz2 aptly-$(VERSION) rm -rf aptly-$(VERSION) diff --git a/deb/list.go b/deb/list.go index b615b5d2..4d379cad 100644 --- a/deb/list.go +++ b/deb/list.go @@ -101,7 +101,7 @@ func (l *PackageList) Add(p *Package) error { l.providesIndex[provides] = append(l.providesIndex[provides], p) } - i := sort.Search(len(l.packagesIndex), func(j int) bool { return l.packagesIndex[j].Name >= p.Name }) + i := sort.Search(len(l.packagesIndex), func(j int) bool { return l.lessPackages(p, l.packagesIndex[j]) }) // insert p into l.packagesIndex in position i l.packagesIndex = append(l.packagesIndex, nil) @@ -300,9 +300,17 @@ func (l *PackageList) Swap(i, j int) { l.packagesIndex[i], l.packagesIndex[j] = l.packagesIndex[j], l.packagesIndex[i] } -// Compare compares two names in lexographical order +func (l *PackageList) lessPackages(iPkg, jPkg *Package) bool { + if iPkg.Name == jPkg.Name { + return CompareVersions(iPkg.Version, jPkg.Version) == 1 + } + + return iPkg.Name < jPkg.Name +} + +// Less compares two packages by name (lexographical) and version (latest to oldest) func (l *PackageList) Less(i, j int) bool { - return l.packagesIndex[i].Name < l.packagesIndex[j].Name + return l.lessPackages(l.packagesIndex[i], l.packagesIndex[j]) } // PrepareIndex prepares list for indexing diff --git a/deb/list_test.go b/deb/list_test.go index 953f5e85..5a7db3be 100644 --- a/deb/list_test.go +++ b/deb/list_test.go @@ -218,6 +218,9 @@ func (s *PackageListSuite) TestSearch(c *C) { c.Check(s.il.Search(Dependency{Architecture: "i386", Pkg: "app", Relation: VersionGreaterOrEqual, Version: "1.0"}), Equals, s.packages[3]) c.Check(s.il.Search(Dependency{Architecture: "i386", Pkg: "app", Relation: VersionGreaterOrEqual, Version: "1.1~bp1"}), Equals, s.packages[3]) c.Check(s.il.Search(Dependency{Architecture: "i386", Pkg: "app", Relation: VersionGreaterOrEqual, Version: "1.2"}), IsNil) + + // search w/o version should return package with latest version + c.Check(s.il.Search(Dependency{Architecture: "source", Pkg: "dpkg"}), Equals, s.packages[13]) } func (s *PackageListSuite) TestFilter(c *C) {