2011-11-29 19:19:32 +00:00
|
|
|
/*
|
2018-01-04 00:52:49 +00:00
|
|
|
Copyright 2011 The Perkeep Authors
|
2011-11-29 19:19:32 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package index
|
|
|
|
|
2011-11-29 20:40:33 +00:00
|
|
|
import (
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"net/url"
|
2016-05-12 04:05:43 +00:00
|
|
|
"time"
|
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/schema"
|
|
|
|
"perkeep.org/pkg/types/camtypes"
|
2011-11-29 20:40:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var urle = url.QueryEscape
|
|
|
|
|
|
|
|
func urld(s string) string {
|
|
|
|
d, _ := url.QueryUnescape(s)
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2011-11-29 19:19:32 +00:00
|
|
|
type dupSkipper struct {
|
|
|
|
m map[string]bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// not thread safe.
|
|
|
|
func (s *dupSkipper) Dup(v string) bool {
|
|
|
|
if s.m == nil {
|
|
|
|
s.m = make(map[string]bool)
|
|
|
|
}
|
|
|
|
if s.m[v] {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
s.m[v] = true
|
|
|
|
return false
|
|
|
|
}
|
2016-05-12 04:05:43 +00:00
|
|
|
|
|
|
|
// claimPtrsAttrValue returns the value of attr from claims,
|
|
|
|
// or the empty string if not found.
|
|
|
|
// Claims should be sorted by claim.Date.
|
2018-01-31 18:30:47 +00:00
|
|
|
func claimPtrsAttrValue(claims []*camtypes.Claim, attr string, at time.Time, signerFilter SignerRefSet) string {
|
2016-05-12 04:05:43 +00:00
|
|
|
return claimsIntfAttrValue(claimPtrSlice(claims), attr, at, signerFilter)
|
|
|
|
}
|
|
|
|
|
|
|
|
type claimsIntf interface {
|
|
|
|
Len() int
|
|
|
|
Claim(i int) *camtypes.Claim
|
|
|
|
}
|
|
|
|
|
|
|
|
type claimSlice []camtypes.Claim
|
|
|
|
|
|
|
|
func (s claimSlice) Len() int { return len(s) }
|
|
|
|
func (s claimSlice) Claim(i int) *camtypes.Claim { return &s[i] }
|
|
|
|
|
|
|
|
type claimPtrSlice []*camtypes.Claim
|
|
|
|
|
|
|
|
func (s claimPtrSlice) Len() int { return len(s) }
|
|
|
|
func (s claimPtrSlice) Claim(i int) *camtypes.Claim { return s[i] }
|
|
|
|
|
2016-11-19 08:58:13 +00:00
|
|
|
// claimsIntfAttrValue finds the value of an attribute in a list of claims
|
|
|
|
// or empty string if not found. claims must be non-nil.
|
2018-01-19 18:53:44 +00:00
|
|
|
// If signerFilter contains any refs, a claim is only taken into account if it
|
|
|
|
// has been signed by one of the given signer refs.
|
2018-01-31 18:30:47 +00:00
|
|
|
func claimsIntfAttrValue(claims claimsIntf, attr string, at time.Time, signerFilter SignerRefSet) string {
|
2016-11-19 08:58:13 +00:00
|
|
|
if claims == nil {
|
|
|
|
panic("nil claims argument in claimsIntfAttrValue")
|
|
|
|
}
|
|
|
|
|
2016-05-12 04:05:43 +00:00
|
|
|
if at.IsZero() {
|
|
|
|
at = time.Now()
|
|
|
|
}
|
2016-05-12 04:05:43 +00:00
|
|
|
|
|
|
|
// use a small static buffer as it speeds up
|
|
|
|
// search.BenchmarkQueryPermanodeLocation by 6-7%
|
|
|
|
// with go 1.7.1
|
|
|
|
var buf [8]string
|
|
|
|
v := buf[:][:0]
|
|
|
|
|
2016-05-12 04:05:43 +00:00
|
|
|
for i := 0; i < claims.Len(); i++ {
|
|
|
|
cl := claims.Claim(i)
|
|
|
|
if cl.Attr != attr || cl.Date.After(at) {
|
|
|
|
continue
|
|
|
|
}
|
2018-01-19 18:53:44 +00:00
|
|
|
|
|
|
|
if len(signerFilter) > 0 {
|
|
|
|
if !signerFilter.blobMatches(cl.Signer) {
|
|
|
|
continue
|
|
|
|
}
|
2016-05-12 04:05:43 +00:00
|
|
|
}
|
2018-01-19 18:53:44 +00:00
|
|
|
|
2016-05-12 04:05:43 +00:00
|
|
|
switch cl.Type {
|
|
|
|
case string(schema.DelAttributeClaim):
|
|
|
|
if cl.Value == "" {
|
|
|
|
v = v[:0]
|
|
|
|
} else {
|
|
|
|
i := 0
|
|
|
|
for _, w := range v {
|
|
|
|
if w != cl.Value {
|
|
|
|
v[i] = w
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v = v[:i]
|
|
|
|
}
|
|
|
|
case string(schema.SetAttributeClaim):
|
|
|
|
v = append(v[:0], cl.Value)
|
|
|
|
case string(schema.AddAttributeClaim):
|
|
|
|
v = append(v, cl.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(v) != 0 {
|
|
|
|
return v[0]
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|