diff --git a/converger/converger.go b/converger/converger.go index e7a00159..178b4f71 100644 --- a/converger/converger.go +++ b/converger/converger.go @@ -85,7 +85,7 @@ type cuid struct { } // NewConverger builds a new converger struct. -func NewConverger(timeout int, stateFn func(bool) error) *converger { +func NewConverger(timeout int, stateFn func(bool) error) Converger { return &converger{ timeout: timeout, stateFn: stateFn, diff --git a/etcd/etcd.go b/etcd/etcd.go index 3351b0dc..64529c8b 100644 --- a/etcd/etcd.go +++ b/etcd/etcd.go @@ -529,8 +529,9 @@ func (obj *EmbdEtcd) CtxError(ctx context.Context, err error) (context.Context, if obj.ctxErr != nil { // stop on permanent error return ctx, obj.ctxErr } - const ctxErr = "ctxErr" - const ctxIter = "ctxIter" + type ctxKey string // use a non-basic type as ctx key (str can conflict) + const ctxErr ctxKey = "ctxErr" + const ctxIter ctxKey = "ctxIter" expBackoff := func(tmin, texp, iter, tmax int) time.Duration { // https://en.wikipedia.org/wiki/Exponential_backoff // tmin <= texp^iter - 1 <= tmax // TODO: check my math diff --git a/remote/remote.go b/remote/remote.go index 1d884cee..2039a651 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -692,7 +692,7 @@ type Remotes struct { fileWatch chan string cConns uint16 // number of concurrent ssh connections, zero means unlimited interactive bool // allow interactive prompting - sshPrivIdRsa string // path to ~/.ssh/id_rsa + sshPrivIDRsa string // path to ~/.ssh/id_rsa caching bool // whether to try and cache the copy of the binary depth uint16 // depth of this node in the remote execution hierarchy prefix string // folder prefix to use for misc storage @@ -715,7 +715,7 @@ type Remotes struct { } // NewRemotes builds a Remotes struct. -func NewRemotes(clientURLs, remoteURLs []string, noop bool, remotes []string, fileWatch chan string, cConns uint16, interactive bool, sshPrivIdRsa string, caching bool, depth uint16, prefix string, converger cv.Converger, convergerCb func(func(map[string]bool) error) (func(), error), flags Flags) *Remotes { +func NewRemotes(clientURLs, remoteURLs []string, noop bool, remotes []string, fileWatch chan string, cConns uint16, interactive bool, sshPrivIDRsa string, caching bool, depth uint16, prefix string, converger cv.Converger, convergerCb func(func(map[string]bool) error) (func(), error), flags Flags) *Remotes { return &Remotes{ clientURLs: clientURLs, remoteURLs: remoteURLs, @@ -724,7 +724,7 @@ func NewRemotes(clientURLs, remoteURLs []string, noop bool, remotes []string, fi fileWatch: fileWatch, cConns: cConns, interactive: interactive, - sshPrivIdRsa: sshPrivIdRsa, + sshPrivIDRsa: sshPrivIDRsa, caching: caching, depth: depth, prefix: prefix, @@ -832,18 +832,18 @@ func (obj *Remotes) NewSSH(file string) (*SSH, error) { // sshKeyAuth is a helper function to get the ssh key auth struct needed func (obj *Remotes) sshKeyAuth() (ssh.AuthMethod, error) { - if obj.sshPrivIdRsa == "" { + if obj.sshPrivIDRsa == "" { return nil, fmt.Errorf("empty path specified") } p := "" // TODO: this doesn't match strings of the form: ~james/.ssh/id_rsa - if strings.HasPrefix(obj.sshPrivIdRsa, "~/") { + if strings.HasPrefix(obj.sshPrivIDRsa, "~/") { usr, err := user.Current() if err != nil { log.Printf("Remote: Can't find home directory automatically.") return nil, err } - p = path.Join(usr.HomeDir, obj.sshPrivIdRsa[len("~/"):]) + p = path.Join(usr.HomeDir, obj.sshPrivIDRsa[len("~/"):]) } if p == "" { return nil, fmt.Errorf("empty path specified") diff --git a/resources/packagekit/packagekit.go b/resources/packagekit/packagekit.go index f00f97f7..2c727091 100644 --- a/resources/packagekit/packagekit.go +++ b/resources/packagekit/packagekit.go @@ -33,8 +33,8 @@ import ( // global tweaks of verbosity and code path const ( - PK_DEBUG = false - PARANOID = false // enable if you see any ghosts + Debug = false + Paranoid = false // enable if you see any ghosts ) // constants which might need to be tweaked or which contain special dbus strings. @@ -74,76 +74,76 @@ var ( //type enum_filter uint64 // https://github.com/hughsie/PackageKit/blob/master/lib/packagekit-glib2/pk-enum.c const ( //static const PkEnumMatch enum_filter[] - PK_FILTER_ENUM_UNKNOWN uint64 = 1 << iota // "unknown" - PK_FILTER_ENUM_NONE // "none" - PK_FILTER_ENUM_INSTALLED // "installed" - PK_FILTER_ENUM_NOT_INSTALLED // "~installed" - PK_FILTER_ENUM_DEVELOPMENT // "devel" - PK_FILTER_ENUM_NOT_DEVELOPMENT // "~devel" - PK_FILTER_ENUM_GUI // "gui" - PK_FILTER_ENUM_NOT_GUI // "~gui" - PK_FILTER_ENUM_FREE // "free" - PK_FILTER_ENUM_NOT_FREE // "~free" - PK_FILTER_ENUM_VISIBLE // "visible" - PK_FILTER_ENUM_NOT_VISIBLE // "~visible" - PK_FILTER_ENUM_SUPPORTED // "supported" - PK_FILTER_ENUM_NOT_SUPPORTED // "~supported" - PK_FILTER_ENUM_BASENAME // "basename" - PK_FILTER_ENUM_NOT_BASENAME // "~basename" - PK_FILTER_ENUM_NEWEST // "newest" - PK_FILTER_ENUM_NOT_NEWEST // "~newest" - PK_FILTER_ENUM_ARCH // "arch" - PK_FILTER_ENUM_NOT_ARCH // "~arch" - PK_FILTER_ENUM_SOURCE // "source" - PK_FILTER_ENUM_NOT_SOURCE // "~source" - PK_FILTER_ENUM_COLLECTIONS // "collections" - PK_FILTER_ENUM_NOT_COLLECTIONS // "~collections" - PK_FILTER_ENUM_APPLICATION // "application" - PK_FILTER_ENUM_NOT_APPLICATION // "~application" - PK_FILTER_ENUM_DOWNLOADED // "downloaded" - PK_FILTER_ENUM_NOT_DOWNLOADED // "~downloaded" + PkFilterEnumUnknown uint64 = 1 << iota // "unknown" + PkFilterEnumNone // "none" + PkFilterEnumInstalled // "installed" + PkFilterEnumNotInstalled // "~installed" + PkFilterEnumDevelopment // "devel" + PkFilterEnumNotDevelopment // "~devel" + PkFilterEnumGui // "gui" + PkFilterEnumNotGui // "~gui" + PkFilterEnumFree // "free" + PkFilterEnumNotFree // "~free" + PkFilterEnumVisible // "visible" + PkFilterEnumNotVisible // "~visible" + PkFilterEnumSupported // "supported" + PkFilterEnumNotSupported // "~supported" + PkFilterEnumBasename // "basename" + PkFilterEnumNotBasename // "~basename" + PkFilterEnumNewest // "newest" + PkFilterEnumNotNewest // "~newest" + PkFilterEnumArch // "arch" + PkFilterEnumNotArch // "~arch" + PkFilterEnumSource // "source" + PkFilterEnumNotSource // "~source" + PkFilterEnumCollections // "collections" + PkFilterEnumNotCollections // "~collections" + PkFilterEnumApplication // "application" + PkFilterEnumNotApplication // "~application" + PkFilterEnumDownloaded // "downloaded" + PkFilterEnumNotDownloaded // "~downloaded" ) // constants from packagekit c library. const ( //static const PkEnumMatch enum_transaction_flag[] - PK_TRANSACTION_FLAG_ENUM_NONE uint64 = 1 << iota // "none" - PK_TRANSACTION_FLAG_ENUM_ONLY_TRUSTED // "only-trusted" - PK_TRANSACTION_FLAG_ENUM_SIMULATE // "simulate" - PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD // "only-download" - PK_TRANSACTION_FLAG_ENUM_ALLOW_REINSTALL // "allow-reinstall" - PK_TRANSACTION_FLAG_ENUM_JUST_REINSTALL // "just-reinstall" - PK_TRANSACTION_FLAG_ENUM_ALLOW_DOWNGRADE // "allow-downgrade" + PkTransactionFlagEnumNone uint64 = 1 << iota // "none" + PkTransactionFlagEnumOnlyTrusted // "only-trusted" + PkTransactionFlagEnumSimulate // "simulate" + PkTransactionFlagEnumOnlyDownload // "only-download" + PkTransactionFlagEnumAllowReinstall // "allow-reinstall" + PkTransactionFlagEnumJustReinstall // "just-reinstall" + PkTransactionFlagEnumAllowDowngrade // "allow-downgrade" ) // constants from packagekit c library. const ( //typedef enum - PK_INFO_ENUM_UNKNOWN uint64 = 1 << iota - PK_INFO_ENUM_INSTALLED - PK_INFO_ENUM_AVAILABLE - PK_INFO_ENUM_LOW - PK_INFO_ENUM_ENHANCEMENT - PK_INFO_ENUM_NORMAL - PK_INFO_ENUM_BUGFIX - PK_INFO_ENUM_IMPORTANT - PK_INFO_ENUM_SECURITY - PK_INFO_ENUM_BLOCKED - PK_INFO_ENUM_DOWNLOADING - PK_INFO_ENUM_UPDATING - PK_INFO_ENUM_INSTALLING - PK_INFO_ENUM_REMOVING - PK_INFO_ENUM_CLEANUP - PK_INFO_ENUM_OBSOLETING - PK_INFO_ENUM_COLLECTION_INSTALLED - PK_INFO_ENUM_COLLECTION_AVAILABLE - PK_INFO_ENUM_FINISHED - PK_INFO_ENUM_REINSTALLING - PK_INFO_ENUM_DOWNGRADING - PK_INFO_ENUM_PREPARING - PK_INFO_ENUM_DECOMPRESSING - PK_INFO_ENUM_UNTRUSTED - PK_INFO_ENUM_TRUSTED - PK_INFO_ENUM_UNAVAILABLE - PK_INFO_ENUM_LAST + PkInfoEnumUnknown uint64 = 1 << iota + PkInfoEnumInstalled + PkInfoEnumAvailable + PkInfoEnumLow + PkInfoEnumEnhancement + PkInfoEnumNormal + PkInfoEnumBugfix + PkInfoEnumImportant + PkInfoEnumSecurity + PkInfoEnumBlocked + PkInfoEnumDownloading + PkInfoEnumUpdating + PkInfoEnumInstalling + PkInfoEnumRemoving + PkInfoEnumCleanup + PkInfoEnumObsoleting + PkInfoEnumCollectionInstalled + PkInfoEnumCollectionAvailable + PkInfoEnumFinished + PkInfoEnumReinstalling + PkInfoEnumDowngrading + PkInfoEnumPreparing + PkInfoEnumDecompressing + PkInfoEnumUntrusted + PkInfoEnumTrusted + PkInfoEnumUnavailable + PkInfoEnumLast ) // Conn is a wrapper struct so we can pass bus connection around in the struct. @@ -184,7 +184,7 @@ func (bus *Conn) Close() error { // internal helper to add signal matches to the bus, should only be called once func (bus *Conn) matchSignal(ch chan *dbus.Signal, path dbus.ObjectPath, iface string, signals []string) error { - if PK_DEBUG { + if Debug { log.Printf("PackageKit: matchSignal(%v, %v, %v, %v)", ch, path, iface, signals) } // eg: gdbus monitor --system --dest org.freedesktop.PackageKit --object-path /org/freedesktop/PackageKit | grep @@ -224,7 +224,7 @@ func (bus *Conn) WatchChanges() (chan *dbus.Signal, error) { if err != nil { return nil, err } - if PARANOID { // TODO: this filtering might not be necessary anymore... + if Paranoid { // TODO: this filtering might not be necessary anymore... // try to handle the filtering inside this function! rch := make(chan *dbus.Signal) go func() { @@ -257,7 +257,7 @@ func (bus *Conn) WatchChanges() (chan *dbus.Signal, error) { // CreateTransaction creates and returns a transaction path. func (bus *Conn) CreateTransaction() (dbus.ObjectPath, error) { - if PK_DEBUG { + if Debug { log.Println("PackageKit: CreateTransaction()") } var interfacePath dbus.ObjectPath @@ -266,7 +266,7 @@ func (bus *Conn) CreateTransaction() (dbus.ObjectPath, error) { if call != nil { return "", call } - if PK_DEBUG { + if Debug { log.Printf("PackageKit: CreateTransaction(): %v", interfacePath) } return interfacePath, nil @@ -284,12 +284,12 @@ func (bus *Conn) ResolvePackages(packages []string, filter uint64) ([]string, er // add signal matches for Package and Finished which will always be last var signals = []string{"Package", "Finished", "Error", "Destroy"} bus.matchSignal(ch, interfacePath, PkIfaceTransaction, signals) - if PK_DEBUG { + if Debug { log.Printf("PackageKit: ResolvePackages(): Object(%v, %v)", PkIface, interfacePath) } obj := bus.GetBus().Object(PkIface, interfacePath) // pass in found transaction path call := obj.Call(FmtTransactionMethod("Resolve"), 0, filter, packages) - if PK_DEBUG { + if Debug { log.Println("PackageKit: ResolvePackages(): Call: Success!") } if call.Err != nil { @@ -300,7 +300,7 @@ loop: // FIXME: add a timeout option to error in case signals are dropped! select { case signal := <-ch: - if PK_DEBUG { + if Debug { log.Printf("PackageKit: ResolvePackages(): Signal: %+v", signal) } if signal.Path != interfacePath { @@ -338,8 +338,8 @@ loop: // IsInstalledList queries a list of packages to see if they are installed. func (bus *Conn) IsInstalledList(packages []string) ([]bool, error) { - var filter uint64 // initializes at the "zero" value of 0 - filter += PK_FILTER_ENUM_ARCH // always search in our arch + var filter uint64 // initializes at the "zero" value of 0 + filter += PkFilterEnumArch // always search in our arch packageIDs, e := bus.ResolvePackages(packages, filter) if e != nil { return nil, fmt.Errorf("ResolvePackages error: %v", e) @@ -593,7 +593,7 @@ loop: // GetUpdates gets a list of packages that are installed and which can be updated, mod filter. func (bus *Conn) GetUpdates(filter uint64) ([]string, error) { - if PK_DEBUG { + if Debug { log.Println("PackageKit: GetUpdates()") } packageIDs := []string{} @@ -664,11 +664,11 @@ func (bus *Conn) PackagesToPackageIDs(packageMap map[string]string, filter uint6 count++ } - if !(filter&PK_FILTER_ENUM_ARCH == PK_FILTER_ENUM_ARCH) { - filter += PK_FILTER_ENUM_ARCH // always search in our arch + if !(filter&PkFilterEnumArch == PkFilterEnumArch) { + filter += PkFilterEnumArch // always search in our arch } - if PK_DEBUG { + if Debug { log.Printf("PackageKit: PackagesToPackageIDs(): %v", strings.Join(packages, ", ")) } resolved, e := bus.ResolvePackages(packages, filter) @@ -771,7 +771,7 @@ func (bus *Conn) PackagesToPackageIDs(packageMap map[string]string, filter uint6 // this check is for packages that need to verify their "newest" status // we need to know this so we can install the correct newest packageID! recursion := make(map[string]*PkPackageIDActionData) - if !(filter&PK_FILTER_ENUM_NEWEST == PK_FILTER_ENUM_NEWEST) { + if !(filter&PkFilterEnumNewest == PkFilterEnumNewest) { checkPackages := []string{} filteredPackageMap := make(map[string]string) for index, pkg := range packages { @@ -788,13 +788,13 @@ func (bus *Conn) PackagesToPackageIDs(packageMap map[string]string, filter uint6 } // we _could_ do a second resolve and then parse like this... - //resolved, e := bus.ResolvePackages(..., filter+PK_FILTER_ENUM_NEWEST) + //resolved, e := bus.ResolvePackages(..., filter+PkFilterEnumNewest) // but that's basically what recursion here could do too! if len(checkPackages) > 0 { - if PK_DEBUG { + if Debug { log.Printf("PackageKit: PackagesToPackageIDs(): Recurse: %v", strings.Join(checkPackages, ", ")) } - recursion, e = bus.PackagesToPackageIDs(filteredPackageMap, filter+PK_FILTER_ENUM_NEWEST) + recursion, e = bus.PackagesToPackageIDs(filteredPackageMap, filter+PkFilterEnumNewest) if e != nil { return nil, fmt.Errorf("Recursion error: %v", e) } diff --git a/resources/pkg.go b/resources/pkg.go index 70b89634..2e4925e1 100644 --- a/resources/pkg.go +++ b/resources/pkg.go @@ -177,22 +177,22 @@ func (obj *PkgRes) groupMappingHelper() map[string]string { } func (obj *PkgRes) pkgMappingHelper(bus *packagekit.Conn) (map[string]*packagekit.PkPackageIDActionData, error) { - packageMap := obj.groupMappingHelper() // get the grouped values - packageMap[obj.Name] = obj.State // key is pkg name, value is pkg state - var filter uint64 // initializes at the "zero" value of 0 - filter += packagekit.PK_FILTER_ENUM_ARCH // always search in our arch (optional!) + packageMap := obj.groupMappingHelper() // get the grouped values + packageMap[obj.Name] = obj.State // key is pkg name, value is pkg state + var filter uint64 // initializes at the "zero" value of 0 + filter += packagekit.PkFilterEnumArch // always search in our arch (optional!) // we're requesting latest version, or to narrow down install choices! if obj.State == "newest" || obj.State == "installed" { // if we add this, we'll still see older packages if installed // this is an optimization, and is *optional*, this logic is // handled inside of PackagesToPackageIDs now automatically! - filter += packagekit.PK_FILTER_ENUM_NEWEST // only search for newest packages + filter += packagekit.PkFilterEnumNewest // only search for newest packages } if !obj.AllowNonFree { - filter += packagekit.PK_FILTER_ENUM_FREE + filter += packagekit.PkFilterEnumFree } if !obj.AllowUnsupported { - filter += packagekit.PK_FILTER_ENUM_SUPPORTED + filter += packagekit.PkFilterEnumSupported } result, err := bus.PackagesToPackageIDs(packageMap, filter) if err != nil { @@ -298,7 +298,7 @@ func (obj *PkgRes) CheckApply(apply bool) (checkOK bool, err error) { var transactionFlags uint64 // initializes at the "zero" value of 0 if !obj.AllowUntrusted { // allow - transactionFlags += packagekit.PK_TRANSACTION_FLAG_ENUM_ONLY_TRUSTED + transactionFlags += packagekit.PkTransactionFlagEnumOnlyTrusted } // apply correct state! log.Printf("%s: Set: %v...", obj.fmtNames(util.StrListIntersection(applyPackages, obj.getNames())), obj.State) diff --git a/resources/resources.go b/resources/resources.go index 757b5ec2..70c4522a 100644 --- a/resources/resources.go +++ b/resources/resources.go @@ -533,7 +533,7 @@ func (obj *BaseRes) Compare(res Res) bool { // if resources are grouped, are the groups the same? if i, j := obj.GetGroup(), res.GetGroup(); len(i) != len(j) { return false - } else { + } else if len(i) > 0 { // trick the golinter ix, jx := Sort(i), Sort(j) for k := range ix { if !ix[k].Compare(jx[k]) { // compare sub resources diff --git a/test/test-golint.sh b/test/test-golint.sh index 48b35e62..be5b7531 100755 --- a/test/test-golint.sh +++ b/test/test-golint.sh @@ -9,7 +9,7 @@ echo running test-golint.sh # FIXME: test a range of commits, since only the last patch is checked here PREVIOUS='HEAD^' CURRENT='HEAD' -THRESHOLD=5 # percent problems per new LOC +THRESHOLD=1 # percent problems per new LOC XPWD=`pwd` ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir! cd "${ROOT}" >/dev/null diff --git a/test/test-gometalinter.sh b/test/test-gometalinter.sh index 8df59850..cb85a3ac 100755 --- a/test/test-gometalinter.sh +++ b/test/test-gometalinter.sh @@ -25,7 +25,7 @@ gml='gometalinter --disable-all' #gml="$gml --enable=goconst" #gml="$gml --enable=gocyclo" gml="$gml --enable=goimports" -#gml="$gml --enable=golint" # TODO: only a few fixes needed +gml="$gml --enable=golint" #gml="$gml --enable=gosimple" # TODO: only a few fixes needed gml="$gml --enable=gotype" #gml="$gml --enable=ineffassign" # TODO: only a few fixes needed