mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-04 05:10:40 +00:00
Merge pull request #509 from smira/golint-govet
Add govet/golint into Travis CI build
This commit is contained in:
@@ -35,8 +35,10 @@ coverage: coverage.out
|
||||
rm -f coverage.out
|
||||
|
||||
check:
|
||||
go vet -shadow=true $(ALL_PACKAGES:%=./%)
|
||||
golint $(ALL_PACKAGES:%=./%)
|
||||
go vet $(ALL_PACKAGES:%=./%)
|
||||
for package in $(ALL_PACKAGES); do \
|
||||
golint ./$$package; \
|
||||
done
|
||||
|
||||
install:
|
||||
go install -v
|
||||
@@ -46,7 +48,7 @@ system-test: install
|
||||
if [ ! -e ~/aptly-fixture-pool ]; then git clone https://github.com/aptly-dev/aptly-fixture-pool.git ~/aptly-fixture-pool/; fi
|
||||
PATH=$(BINPATH)/:$(PATH) $(PYTHON) system/run.py --long $(TESTS)
|
||||
|
||||
travis: $(TRAVIS_TARGET) system-test
|
||||
travis: $(TRAVIS_TARGET) check system-test
|
||||
|
||||
test:
|
||||
go test -v `go list ./... | grep -v vendor/` -gocheck.v=true
|
||||
|
||||
+7
-6
@@ -3,12 +3,13 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/smira/aptly/aptly"
|
||||
"github.com/smira/aptly/deb"
|
||||
"github.com/smira/aptly/query"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Lock order acquisition (canonical):
|
||||
@@ -23,8 +24,8 @@ func apiVersion(c *gin.Context) {
|
||||
}
|
||||
|
||||
const (
|
||||
ACQUIREDB = iota
|
||||
RELEASEDB
|
||||
acquiredb = iota
|
||||
releasedb
|
||||
)
|
||||
|
||||
// Flushes all collections which cache in-memory objects
|
||||
@@ -80,14 +81,14 @@ func acquireDatabase(requests chan int, acks chan error) {
|
||||
for {
|
||||
request := <-requests
|
||||
switch request {
|
||||
case ACQUIREDB:
|
||||
case acquiredb:
|
||||
if clients == 0 {
|
||||
acks <- context.ReOpenDatabase()
|
||||
} else {
|
||||
acks <- nil
|
||||
}
|
||||
clients++
|
||||
case RELEASEDB:
|
||||
case releasedb:
|
||||
clients--
|
||||
if clients == 0 {
|
||||
flushColections()
|
||||
|
||||
+4
-3
@@ -1,9 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
ctx "github.com/smira/aptly/context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var context *ctx.AptlyContext
|
||||
@@ -26,14 +27,14 @@ func Router(c *ctx.AptlyContext) http.Handler {
|
||||
go cacheFlusher(requests, acks)
|
||||
|
||||
router.Use(func(c *gin.Context) {
|
||||
requests <- ACQUIREDB
|
||||
requests <- acquiredb
|
||||
err := <-acks
|
||||
if err != nil {
|
||||
c.Fail(500, err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
requests <- RELEASEDB
|
||||
requests <- releasedb
|
||||
err = <-acks
|
||||
if err != nil {
|
||||
c.Fail(500, err)
|
||||
|
||||
+1
-1
@@ -3,5 +3,5 @@ package aptly
|
||||
// Version of aptly
|
||||
const Version = "0.9.8~dev"
|
||||
|
||||
// Enable debugging features?
|
||||
// EnableDebug triggers some debugging features
|
||||
const EnableDebug = false
|
||||
|
||||
@@ -2,14 +2,15 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
|
||||
"github.com/smira/aptly/deb"
|
||||
"github.com/smira/aptly/query"
|
||||
"github.com/smira/aptly/utils"
|
||||
"github.com/smira/commander"
|
||||
"github.com/smira/flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
||||
@@ -88,7 +89,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
||||
|
||||
defer func() {
|
||||
// on any interruption, unlock the mirror
|
||||
err := context.ReOpenDatabase()
|
||||
err = context.ReOpenDatabase()
|
||||
if err == nil {
|
||||
repo.MarkAsIdle()
|
||||
context.CollectionFactory().RemoteRepoCollection().Update(repo)
|
||||
@@ -130,7 +131,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
||||
}()
|
||||
|
||||
// Wait for all downloads to finish
|
||||
errors := make([]string, 0)
|
||||
var errors []string
|
||||
|
||||
for count > 0 {
|
||||
select {
|
||||
@@ -149,7 +150,7 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
||||
signal.Stop(sigch)
|
||||
|
||||
if len(errors) > 0 {
|
||||
return fmt.Errorf("unable to update: download errors:\n %s\n", strings.Join(errors, "\n "))
|
||||
return fmt.Errorf("unable to update: download errors:\n %s", strings.Join(errors, "\n "))
|
||||
}
|
||||
|
||||
err = context.ReOpenDatabase()
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ func aptlyTaskRun(cmd *commander.Command, args []string) error {
|
||||
|
||||
var finfo os.FileInfo
|
||||
if finfo, err = os.Stat(filename); os.IsNotExist(err) || finfo.IsDir() {
|
||||
return fmt.Errorf("no such file, %s\n", filename)
|
||||
return fmt.Errorf("no such file, %s", filename)
|
||||
}
|
||||
|
||||
fmt.Print("Reading file...\n\n")
|
||||
|
||||
+4
-2
@@ -2,9 +2,10 @@ package deb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/smira/aptly/aptly"
|
||||
"github.com/smira/aptly/utils"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// Dependency options
|
||||
@@ -66,6 +67,7 @@ func NewPackageList() *PackageList {
|
||||
return NewPackageListWithDuplicates(false, 1000)
|
||||
}
|
||||
|
||||
// NewPackageListWithDuplicates creates empty package list which might allow or block duplicate packages
|
||||
func NewPackageListWithDuplicates(duplicates bool, capacity int) *PackageList {
|
||||
if capacity == 0 {
|
||||
capacity = 1000
|
||||
@@ -247,7 +249,7 @@ func (l *PackageList) Strings() []string {
|
||||
|
||||
for _, p := range l.packages {
|
||||
result[i] = string(p.Key(""))
|
||||
i += 1
|
||||
i++
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
@@ -64,9 +64,9 @@ func (s *PackageCollectionSuite) TestByKey(c *C) {
|
||||
c.Check(p2.Files()[0].Filename, Equals, "alien-arena-common_7.40-2_i386.deb")
|
||||
}
|
||||
|
||||
func (s *PackageCollectionSuite) TestByKeyOld_0_3(c *C) {
|
||||
func (s *PackageCollectionSuite) TestByKeyOld0_3(c *C) {
|
||||
key := []byte("Pi386 vmware-view-open-client 4.5.0-297975+dfsg-4+b1")
|
||||
s.db.Put(key, old_0_3_Package)
|
||||
s.db.Put(key, old0_3Package)
|
||||
|
||||
p, err := s.collection.ByKey(key)
|
||||
c.Check(err, IsNil)
|
||||
@@ -133,7 +133,7 @@ func (s *PackageCollectionSuite) TestDeleteByKey(c *C) {
|
||||
}
|
||||
|
||||
// This is old package (pre-0.4) that would habe to be converted
|
||||
var old_0_3_Package = []byte{0x8f, 0xac, 0x41, 0x72, 0x63, 0x68, 0x69, 0x74, 0x65, 0x63, 0x74, 0x75, 0x72, 0x65, 0xa4, 0x69, 0x33, 0x38, 0x36,
|
||||
var old0_3Package = []byte{0x8f, 0xac, 0x41, 0x72, 0x63, 0x68, 0x69, 0x74, 0x65, 0x63, 0x74, 0x75, 0x72, 0x65, 0xa4, 0x69, 0x33, 0x38, 0x36,
|
||||
0xac, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x73, 0xc0, 0xb1, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x44, 0x65,
|
||||
0x70, 0x65, 0x6e, 0x64, 0x73, 0x49, 0x6e, 0x44, 0x65, 0x70, 0xc0, 0xa7, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x73, 0xdc, 0x0, 0x12,
|
||||
0xb7, 0x6c, 0x69, 0x62, 0x61, 0x74, 0x6b, 0x31, 0x2e, 0x30, 0x2d, 0x30, 0x20, 0x28, 0x3e, 0x3d, 0x20, 0x31, 0x2e, 0x31, 0x32, 0x2e,
|
||||
|
||||
+2
-2
@@ -921,7 +921,7 @@ func (collection *PublishedRepoCollection) ByUUID(uuid string) (*PublishedRepo,
|
||||
|
||||
// BySnapshot looks up repository by snapshot source
|
||||
func (collection *PublishedRepoCollection) BySnapshot(snapshot *Snapshot) []*PublishedRepo {
|
||||
result := make([]*PublishedRepo, 0)
|
||||
var result []*PublishedRepo
|
||||
for _, r := range collection.list {
|
||||
if r.SourceKind == "snapshot" {
|
||||
if r.SourceUUID == snapshot.UUID {
|
||||
@@ -941,7 +941,7 @@ func (collection *PublishedRepoCollection) BySnapshot(snapshot *Snapshot) []*Pub
|
||||
|
||||
// ByLocalRepo looks up repository by local repo source
|
||||
func (collection *PublishedRepoCollection) ByLocalRepo(repo *LocalRepo) []*PublishedRepo {
|
||||
result := make([]*PublishedRepo, 0)
|
||||
var result []*PublishedRepo
|
||||
for _, r := range collection.list {
|
||||
if r.SourceKind == "local" {
|
||||
if r.SourceUUID == repo.UUID {
|
||||
|
||||
+3
-2
@@ -3,9 +3,10 @@ package deb
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"sort"
|
||||
|
||||
"github.com/AlekSi/pointer"
|
||||
"github.com/ugorji/go/codec"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// PackageRefList is a list of keys of packages, this is basis for snapshot
|
||||
@@ -389,7 +390,7 @@ func (l *PackageRefList) FilterLatestRefs() {
|
||||
}
|
||||
|
||||
// Compensate for the reduced set
|
||||
i -= 1
|
||||
i--
|
||||
}
|
||||
|
||||
lastArch, lastName, lastVer = arch, name, ver
|
||||
|
||||
+21
-20
@@ -2,16 +2,17 @@ package deb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/smira/aptly/aptly"
|
||||
"github.com/smira/aptly/console"
|
||||
"github.com/smira/aptly/database"
|
||||
"github.com/smira/aptly/files"
|
||||
"github.com/smira/aptly/http"
|
||||
"github.com/smira/aptly/utils"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
@@ -197,7 +198,7 @@ func (s *RemoteRepoSuite) TestFetch(c *C) {
|
||||
|
||||
func (s *RemoteRepoSuite) TestFetchNullVerifier1(c *C) {
|
||||
downloader := http.NewFakeDownloader()
|
||||
downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/InRelease", &http.HTTPError{Code: 404})
|
||||
downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/InRelease", &http.Error{Code: 404})
|
||||
downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/Release", exampleReleaseFile)
|
||||
downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/Release.gpg", "GPG")
|
||||
|
||||
@@ -257,8 +258,8 @@ func (s *RemoteRepoSuite) TestDownload(c *C) {
|
||||
err := s.repo.Fetch(s.downloader, nil)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.HTTPError{Code: 404})
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.HTTPError{Code: 404})
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.Error{Code: 404})
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.Error{Code: 404})
|
||||
s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages", examplePackagesFile)
|
||||
|
||||
err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false, 1)
|
||||
@@ -286,11 +287,11 @@ func (s *RemoteRepoSuite) TestDownloadWithSources(c *C) {
|
||||
err := s.repo.Fetch(s.downloader, nil)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.HTTPError{Code: 404})
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.HTTPError{Code: 404})
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.bz2", &http.Error{Code: 404})
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages.gz", &http.Error{Code: 404})
|
||||
s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/binary-i386/Packages", examplePackagesFile)
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.bz2", &http.HTTPError{Code: 404})
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.gz", &http.HTTPError{Code: 404})
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.bz2", &http.Error{Code: 404})
|
||||
s.downloader.ExpectError("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources.gz", &http.Error{Code: 404})
|
||||
s.downloader.ExpectResponse("http://mirror.yandex.ru/debian/dists/squeeze/main/source/Sources", exampleSourcesFile)
|
||||
|
||||
err = s.repo.DownloadPackageIndexes(s.progress, s.downloader, s.collectionFactory, false, 1)
|
||||
@@ -327,9 +328,9 @@ func (s *RemoteRepoSuite) TestDownloadWithSources(c *C) {
|
||||
func (s *RemoteRepoSuite) TestDownloadFlat(c *C) {
|
||||
downloader := http.NewFakeDownloader()
|
||||
downloader.ExpectResponse("http://repos.express42.com/virool/precise/Release", exampleReleaseFile)
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.HTTPError{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.HTTPError{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.xz", &http.HTTPError{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.Error{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.Error{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.xz", &http.Error{Code: 404})
|
||||
downloader.ExpectResponse("http://repos.express42.com/virool/precise/Packages", examplePackagesFile)
|
||||
|
||||
err := s.flat.Fetch(downloader, nil)
|
||||
@@ -358,13 +359,13 @@ func (s *RemoteRepoSuite) TestDownloadWithSourcesFlat(c *C) {
|
||||
|
||||
downloader := http.NewFakeDownloader()
|
||||
downloader.ExpectResponse("http://repos.express42.com/virool/precise/Release", exampleReleaseFile)
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.HTTPError{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.HTTPError{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.xz", &http.HTTPError{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.bz2", &http.Error{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.gz", &http.Error{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Packages.xz", &http.Error{Code: 404})
|
||||
downloader.ExpectResponse("http://repos.express42.com/virool/precise/Packages", examplePackagesFile)
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.bz2", &http.HTTPError{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.gz", &http.HTTPError{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.xz", &http.HTTPError{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.bz2", &http.Error{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.gz", &http.Error{Code: 404})
|
||||
downloader.ExpectError("http://repos.express42.com/virool/precise/Sources.xz", &http.Error{Code: 404})
|
||||
downloader.ExpectResponse("http://repos.express42.com/virool/precise/Sources", exampleSourcesFile)
|
||||
|
||||
err := s.flat.Fetch(downloader, nil)
|
||||
|
||||
+8
-7
@@ -4,15 +4,16 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/smira/aptly/database"
|
||||
"github.com/smira/aptly/utils"
|
||||
"github.com/smira/go-uuid/uuid"
|
||||
"github.com/ugorji/go/codec"
|
||||
"log"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/smira/aptly/database"
|
||||
"github.com/smira/aptly/utils"
|
||||
"github.com/smira/go-uuid/uuid"
|
||||
"github.com/ugorji/go/codec"
|
||||
)
|
||||
|
||||
// Snapshot is immutable state of repository: list of packages
|
||||
@@ -251,7 +252,7 @@ func (collection *SnapshotCollection) ByUUID(uuid string) (*Snapshot, error) {
|
||||
|
||||
// ByRemoteRepoSource looks up snapshots that have specified RemoteRepo as a source
|
||||
func (collection *SnapshotCollection) ByRemoteRepoSource(repo *RemoteRepo) []*Snapshot {
|
||||
result := make([]*Snapshot, 0)
|
||||
var result []*Snapshot
|
||||
|
||||
for _, s := range collection.list {
|
||||
if s.SourceKind == "repo" && utils.StrSliceHasItem(s.SourceIDs, repo.UUID) {
|
||||
@@ -263,7 +264,7 @@ func (collection *SnapshotCollection) ByRemoteRepoSource(repo *RemoteRepo) []*Sn
|
||||
|
||||
// ByLocalRepoSource looks up snapshots that have specified LocalRepo as a source
|
||||
func (collection *SnapshotCollection) ByLocalRepoSource(repo *LocalRepo) []*Snapshot {
|
||||
result := make([]*Snapshot, 0)
|
||||
var result []*Snapshot
|
||||
|
||||
for _, s := range collection.list {
|
||||
if s.SourceKind == "local" && utils.StrSliceHasItem(s.SourceIDs, repo.UUID) {
|
||||
@@ -275,7 +276,7 @@ func (collection *SnapshotCollection) ByLocalRepoSource(repo *LocalRepo) []*Snap
|
||||
|
||||
// BySnapshotSource looks up snapshots that have specified snapshot as a source
|
||||
func (collection *SnapshotCollection) BySnapshotSource(snapshot *Snapshot) []*Snapshot {
|
||||
result := make([]*Snapshot, 0)
|
||||
var result []*Snapshot
|
||||
|
||||
for _, s := range collection.list {
|
||||
if s.SourceKind == "snapshot" && utils.StrSliceHasItem(s.SourceIDs, snapshot.UUID) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package deb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/smira/aptly/database"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
@@ -195,7 +196,7 @@ func (s *SnapshotCollectionSuite) TestFindByRemoteRepoSource(c *C) {
|
||||
|
||||
repo3, _ := NewRemoteRepo("other", "http://mirror.yandex.ru/debian/", "lenny", []string{"main"}, []string{}, false, false)
|
||||
|
||||
c.Check(s.collection.ByRemoteRepoSource(repo3), DeepEquals, []*Snapshot{})
|
||||
c.Check(s.collection.ByRemoteRepoSource(repo3), DeepEquals, []*Snapshot(nil))
|
||||
}
|
||||
|
||||
func (s *SnapshotCollectionSuite) TestFindByLocalRepoSource(c *C) {
|
||||
@@ -209,7 +210,7 @@ func (s *SnapshotCollectionSuite) TestFindByLocalRepoSource(c *C) {
|
||||
|
||||
lrepo3 := NewLocalRepo("other", "")
|
||||
|
||||
c.Check(s.collection.ByLocalRepoSource(lrepo3), DeepEquals, []*Snapshot{})
|
||||
c.Check(s.collection.ByLocalRepoSource(lrepo3), DeepEquals, []*Snapshot(nil))
|
||||
}
|
||||
|
||||
func (s *SnapshotCollectionSuite) TestFindSnapshotSource(c *C) {
|
||||
@@ -225,7 +226,7 @@ func (s *SnapshotCollectionSuite) TestFindSnapshotSource(c *C) {
|
||||
|
||||
c.Check(s.collection.BySnapshotSource(s.snapshot1), DeepEquals, []*Snapshot{snapshot3, snapshot4})
|
||||
c.Check(s.collection.BySnapshotSource(s.snapshot2), DeepEquals, []*Snapshot{snapshot3})
|
||||
c.Check(s.collection.BySnapshotSource(snapshot5), DeepEquals, []*Snapshot{})
|
||||
c.Check(s.collection.BySnapshotSource(snapshot5), DeepEquals, []*Snapshot(nil))
|
||||
}
|
||||
|
||||
func (s *SnapshotCollectionSuite) TestDrop(c *C) {
|
||||
|
||||
+5
-5
@@ -19,14 +19,14 @@ import (
|
||||
"github.com/smira/go-xz"
|
||||
)
|
||||
|
||||
// HTTPError is download error connected to HTTP code
|
||||
type HTTPError struct {
|
||||
// Error is download error connected to HTTP code
|
||||
type Error struct {
|
||||
Code int
|
||||
URL string
|
||||
}
|
||||
|
||||
// Error
|
||||
func (e *HTTPError) Error() string {
|
||||
func (e *Error) Error() string {
|
||||
return fmt.Sprintf("HTTP code %d while fetching %s", e.Code, e.URL)
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ func (downloader *downloaderImpl) downloadTask(req *http.Request, task *download
|
||||
}
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
return "", &HTTPError{Code: resp.StatusCode, URL: task.url}
|
||||
return "", &Error{Code: resp.StatusCode, URL: task.url}
|
||||
}
|
||||
|
||||
err = os.MkdirAll(filepath.Dir(task.destination), 0777)
|
||||
@@ -367,7 +367,7 @@ func DownloadTryCompression(downloader aptly.Downloader, url string, expectedChe
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err1, ok := err.(*HTTPError); ok && (err1.Code == 404 || err1.Code == 403) {
|
||||
if err1, ok := err.(*Error); ok && (err1.Code == 404 || err1.Code == 403) {
|
||||
continue
|
||||
}
|
||||
return nil, nil, err
|
||||
|
||||
+14
-15
@@ -233,7 +233,7 @@ func (s *DownloaderSuite) TestDownloadTryCompression(c *C) {
|
||||
// bzip2 not available, but gz is
|
||||
buf = make([]byte, 4)
|
||||
d = NewFakeDownloader()
|
||||
d.ExpectError("http://example.com/file.bz2", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.bz2", &Error{Code: 404})
|
||||
d.ExpectResponse("http://example.com/file.gz", gzipData)
|
||||
r, file, err = DownloadTryCompression(d, "http://example.com/file", expectedChecksums, false, 1)
|
||||
c.Assert(err, IsNil)
|
||||
@@ -245,8 +245,8 @@ func (s *DownloaderSuite) TestDownloadTryCompression(c *C) {
|
||||
// bzip2 & gzip not available, but xz is
|
||||
buf = make([]byte, 4)
|
||||
d = NewFakeDownloader()
|
||||
d.ExpectError("http://example.com/file.bz2", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.gz", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.bz2", &Error{Code: 404})
|
||||
d.ExpectError("http://example.com/file.gz", &Error{Code: 404})
|
||||
d.ExpectResponse("http://example.com/file.xz", xzData)
|
||||
r, file, err = DownloadTryCompression(d, "http://example.com/file", expectedChecksums, false, 1)
|
||||
c.Assert(err, IsNil)
|
||||
@@ -258,9 +258,9 @@ func (s *DownloaderSuite) TestDownloadTryCompression(c *C) {
|
||||
// bzip2, gzip & xz not available, but raw is
|
||||
buf = make([]byte, 4)
|
||||
d = NewFakeDownloader()
|
||||
d.ExpectError("http://example.com/file.bz2", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.gz", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.xz", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.bz2", &Error{Code: 404})
|
||||
d.ExpectError("http://example.com/file.gz", &Error{Code: 404})
|
||||
d.ExpectError("http://example.com/file.xz", &Error{Code: 404})
|
||||
d.ExpectResponse("http://example.com/file", rawData)
|
||||
r, file, err = DownloadTryCompression(d, "http://example.com/file", expectedChecksums, false, 1)
|
||||
c.Assert(err, IsNil)
|
||||
@@ -270,11 +270,10 @@ func (s *DownloaderSuite) TestDownloadTryCompression(c *C) {
|
||||
c.Assert(d.Empty(), Equals, true)
|
||||
|
||||
// gzip available, but broken
|
||||
buf = make([]byte, 4)
|
||||
d = NewFakeDownloader()
|
||||
d.ExpectError("http://example.com/file.bz2", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.bz2", &Error{Code: 404})
|
||||
d.ExpectResponse("http://example.com/file.gz", "x")
|
||||
r, file, err = DownloadTryCompression(d, "http://example.com/file", nil, true, 1)
|
||||
_, file, err = DownloadTryCompression(d, "http://example.com/file", nil, true, 1)
|
||||
c.Assert(err, ErrorMatches, "unexpected EOF")
|
||||
c.Assert(d.Empty(), Equals, true)
|
||||
}
|
||||
@@ -285,17 +284,17 @@ func (s *DownloaderSuite) TestDownloadTryCompressionErrors(c *C) {
|
||||
c.Assert(err, ErrorMatches, "unexpected request.*")
|
||||
|
||||
d = NewFakeDownloader()
|
||||
d.ExpectError("http://example.com/file.bz2", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.gz", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.xz", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.bz2", &Error{Code: 404})
|
||||
d.ExpectError("http://example.com/file.gz", &Error{Code: 404})
|
||||
d.ExpectError("http://example.com/file.xz", &Error{Code: 404})
|
||||
d.ExpectError("http://example.com/file", errors.New("403"))
|
||||
_, _, err = DownloadTryCompression(d, "http://example.com/file", nil, true, 1)
|
||||
c.Assert(err, ErrorMatches, "403")
|
||||
|
||||
d = NewFakeDownloader()
|
||||
d.ExpectError("http://example.com/file.bz2", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.gz", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.xz", &HTTPError{Code: 404})
|
||||
d.ExpectError("http://example.com/file.bz2", &Error{Code: 404})
|
||||
d.ExpectError("http://example.com/file.gz", &Error{Code: 404})
|
||||
d.ExpectError("http://example.com/file.xz", &Error{Code: 404})
|
||||
d.ExpectResponse("http://example.com/file", rawData)
|
||||
expectedChecksums := map[string]utils.ChecksumInfo{
|
||||
"file.bz2": {Size: 7},
|
||||
|
||||
+7
-7
@@ -28,15 +28,15 @@ type s3Error struct {
|
||||
Code string
|
||||
Message string
|
||||
BucketName string
|
||||
RequestId string
|
||||
HostId string
|
||||
RequestID string
|
||||
HostID string
|
||||
}
|
||||
|
||||
type action struct {
|
||||
srv *Server
|
||||
w http.ResponseWriter
|
||||
req *http.Request
|
||||
reqId string
|
||||
reqID string
|
||||
}
|
||||
|
||||
// Config controls the internal behaviour of the Server. A nil config is the default
|
||||
@@ -62,7 +62,7 @@ func (c *Config) send409Conflict() bool {
|
||||
// All of the data for the server is kept in memory.
|
||||
type Server struct {
|
||||
url string
|
||||
reqId int
|
||||
reqID int
|
||||
listener net.Listener
|
||||
mu sync.Mutex
|
||||
buckets map[string]*bucket
|
||||
@@ -144,9 +144,9 @@ func (srv *Server) serveHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
srv: srv,
|
||||
w: w,
|
||||
req: req,
|
||||
reqId: fmt.Sprintf("%09X", srv.reqId),
|
||||
reqID: fmt.Sprintf("%09X", srv.reqID),
|
||||
}
|
||||
srv.reqId++
|
||||
srv.reqID++
|
||||
|
||||
var r resource
|
||||
defer func() {
|
||||
@@ -158,7 +158,7 @@ func (srv *Server) serveHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
case bucketResource:
|
||||
err.BucketName = r.name
|
||||
}
|
||||
err.RequestId = a.reqId
|
||||
err.RequestID = a.reqID
|
||||
// TODO HostId
|
||||
w.Header().Set("Content-Type", `xml version="1.0" encoding="UTF-8"`)
|
||||
w.WriteHeader(err.statusCode)
|
||||
|
||||
+7
-6
@@ -3,18 +3,19 @@ package swift
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/ncw/swift"
|
||||
"github.com/smira/aptly/aptly"
|
||||
"github.com/smira/aptly/files"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/ncw/swift"
|
||||
"github.com/smira/aptly/aptly"
|
||||
"github.com/smira/aptly/files"
|
||||
)
|
||||
|
||||
// PublishedStorage abstract file system with published files (actually hosted on Swift)
|
||||
type PublishedStorage struct {
|
||||
conn swift.Connection
|
||||
conn *swift.Connection
|
||||
container string
|
||||
prefix string
|
||||
supportBulkDelete bool
|
||||
@@ -51,7 +52,7 @@ func NewPublishedStorage(username string, password string, authURL string, tenan
|
||||
if tenantID == "" {
|
||||
tenantID = os.Getenv("OS_TENANT_ID")
|
||||
}
|
||||
if domain == "" {
|
||||
if domain == "" {
|
||||
domain = os.Getenv("OS_USER_DOMAIN_NAME")
|
||||
}
|
||||
if domainID == "" {
|
||||
@@ -64,7 +65,7 @@ func NewPublishedStorage(username string, password string, authURL string, tenan
|
||||
tenantDomainID = os.Getenv("OS_PROJECT_DOMAIN_ID")
|
||||
}
|
||||
|
||||
ct := swift.Connection{
|
||||
ct := &swift.Connection{
|
||||
UserName: username,
|
||||
ApiKey: password,
|
||||
AuthUrl: authURL,
|
||||
|
||||
@@ -6,4 +6,3 @@ Download queue: 1 items (30 B)
|
||||
Downloading ${url}pool/main/a/amanda/amanda-client_3.3.1-3~bpo60+1_amd64.deb...
|
||||
ERROR: unable to update: download errors:
|
||||
${url}pool/main/a/amanda/amanda-client_3.3.1-3~bpo60+1_amd64.deb: sha1 hash mismatch "8d3a014000038725d6daf8771b42a0784253688f" != "66b27417d37e024c46526c2f6d358a754fc552f3"
|
||||
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
ERROR: no such file, not_found
|
||||
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ func StrSliceDeduplicate(s []string) []string {
|
||||
|
||||
// StrSlicesSubstract finds all the strings which are in l but not in r, both slices shoult be sorted
|
||||
func StrSlicesSubstract(l, r []string) []string {
|
||||
result := make([]string, 0)
|
||||
var result []string
|
||||
|
||||
// pointer to left and right reflists
|
||||
il, ir := 0, 0
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ func (s *ListSuite) TestStrSliceDeduplicate(c *C) {
|
||||
}
|
||||
|
||||
func (s *ListSuite) TestStrSlicesSubstract(c *C) {
|
||||
empty := []string{}
|
||||
empty := []string(nil)
|
||||
l1 := []string{"r1", "r2", "r3", "r4"}
|
||||
l2 := []string{"r1", "r3"}
|
||||
l3 := []string{"r2", "r4"}
|
||||
|
||||
+16
-15
@@ -2,22 +2,23 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"golang.org/x/sys/unix"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// check if directory exists and is accessible
|
||||
// DirIsAccessible verifies that directory exists and is accessible
|
||||
func DirIsAccessible(filename string) error {
|
||||
_, err := os.Stat(filename);
|
||||
if err != nil {
|
||||
if ! os.IsNotExist(err) {
|
||||
return fmt.Errorf("Something went wrong, %v", err)
|
||||
}
|
||||
} else {
|
||||
if unix.Access(filename, unix.W_OK) != nil {
|
||||
return fmt.Errorf("'%s' is inaccessible, check access rights", filename)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
_, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("Something went wrong, %v", err)
|
||||
}
|
||||
} else {
|
||||
if unix.Access(filename, unix.W_OK) != nil {
|
||||
return fmt.Errorf("'%s' is inaccessible, check access rights", filename)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user