2011-11-02 01:37:27 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
"errors"
|
2012-10-08 14:16:00 +00:00
|
|
|
"fmt"
|
2011-11-28 03:29:23 +00:00
|
|
|
"log"
|
2011-11-02 01:37:27 +00:00
|
|
|
"os"
|
2011-11-29 19:40:15 +00:00
|
|
|
"strconv"
|
2011-11-28 03:29:23 +00:00
|
|
|
"strings"
|
2011-11-02 01:37:27 +00:00
|
|
|
"time"
|
|
|
|
|
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
|
|
|
"camlistore.org/pkg/blobref"
|
|
|
|
"camlistore.org/pkg/blobserver"
|
|
|
|
"camlistore.org/pkg/search"
|
2011-11-02 01:37:27 +00:00
|
|
|
)
|
|
|
|
|
2011-11-28 03:29:23 +00:00
|
|
|
var _ = log.Printf
|
|
|
|
|
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
|
|
|
var ErrNotFound = errors.New("index: key not found")
|
2011-11-11 02:58:04 +00:00
|
|
|
|
2013-01-14 04:19:36 +00:00
|
|
|
type Storage interface {
|
2011-11-11 02:58:04 +00:00
|
|
|
// Get gets the value for the given key. It returns ErrNotFound if the DB
|
|
|
|
// does not contain the key.
|
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
|
|
|
Get(key string) (string, error)
|
2011-11-11 02:58:04 +00:00
|
|
|
|
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
|
|
|
Set(key, value string) error
|
|
|
|
Delete(key string) error
|
2011-11-09 16:21:19 +00:00
|
|
|
|
|
|
|
BeginBatch() BatchMutation
|
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
|
|
|
CommitBatch(b BatchMutation) error
|
2011-11-10 18:28:44 +00:00
|
|
|
|
|
|
|
// Find returns an iterator positioned before the first key/value pair
|
|
|
|
// whose key is 'greater than or equal to' the given key. There may be no
|
|
|
|
// such pair, in which case the iterator will return false on Next.
|
|
|
|
//
|
|
|
|
// Any error encountered will be implicitly returned via the iterator. An
|
|
|
|
// error-iterator will yield no key/value pairs and closing that iterator
|
|
|
|
// will return that error.
|
|
|
|
Find(key string) Iterator
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterator iterates over an index Storage's key/value pairs in key order.
|
|
|
|
//
|
|
|
|
// An iterator must be closed after use, but it is not necessary to read an
|
|
|
|
// iterator until exhaustion.
|
|
|
|
//
|
|
|
|
// An iterator is not necessarily goroutine-safe, but it is safe to use
|
|
|
|
// multiple iterators concurrently, with each in a dedicated goroutine.
|
|
|
|
type Iterator interface {
|
|
|
|
// Next moves the iterator to the next key/value pair.
|
2013-01-09 22:21:32 +00:00
|
|
|
// It returns false when the iterator is exhausted.
|
2011-11-10 18:28:44 +00:00
|
|
|
Next() bool
|
|
|
|
|
|
|
|
// Key returns the key of the current key/value pair.
|
|
|
|
// Only valid after a call to Next returns true.
|
|
|
|
Key() string
|
|
|
|
|
|
|
|
// Value returns the value of the current key/value pair.
|
|
|
|
// Only valid after a call to Next returns true.
|
|
|
|
Value() string
|
|
|
|
|
|
|
|
// Close closes the iterator and returns any accumulated error. Exhausting
|
|
|
|
// all the key/value pairs in a table is not considered to be an error.
|
|
|
|
// It is valid to call Close multiple times. Other methods should not be
|
|
|
|
// called after the iterator has been closed.
|
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
|
|
|
Close() error
|
2011-11-09 16:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type BatchMutation interface {
|
|
|
|
Set(key, value string)
|
|
|
|
Delete(key string)
|
|
|
|
}
|
|
|
|
|
2012-02-26 12:49:03 +00:00
|
|
|
type Mutation interface {
|
|
|
|
Key() string
|
|
|
|
Value() string
|
|
|
|
IsDelete() bool
|
|
|
|
}
|
|
|
|
|
2011-11-09 16:21:19 +00:00
|
|
|
type mutation struct {
|
|
|
|
key string
|
|
|
|
value string // used if !delete
|
|
|
|
delete bool // if to be deleted
|
|
|
|
}
|
|
|
|
|
2012-02-26 12:49:03 +00:00
|
|
|
func (m mutation) Key() string {
|
|
|
|
return m.key
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mutation) Value() string {
|
|
|
|
return m.value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mutation) IsDelete() bool {
|
|
|
|
return m.delete
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewBatchMutation() BatchMutation {
|
|
|
|
return &batch{}
|
|
|
|
}
|
|
|
|
|
2011-11-09 16:21:19 +00:00
|
|
|
type batch struct {
|
2012-02-26 12:49:03 +00:00
|
|
|
m []Mutation
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *batch) Mutations() []Mutation {
|
|
|
|
return b.m
|
2011-11-09 16:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *batch) Delete(key string) {
|
|
|
|
b.m = append(b.m, mutation{key: key, delete: true})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *batch) Set(key, value string) {
|
|
|
|
b.m = append(b.m, mutation{key: key, value: value})
|
2011-11-02 01:37:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Index struct {
|
2011-11-07 16:40:31 +00:00
|
|
|
*blobserver.SimpleBlobHubPartitionMap
|
|
|
|
*blobserver.NoImplStorage
|
|
|
|
|
2013-01-14 04:19:36 +00:00
|
|
|
s Storage
|
2011-11-07 16:40:31 +00:00
|
|
|
|
|
|
|
KeyFetcher blobref.StreamingFetcher // for verifying claims
|
|
|
|
|
|
|
|
// Used for fetching blobs to find the complete sha1s of file & bytes
|
|
|
|
// schema blobs.
|
2011-12-03 19:26:42 +00:00
|
|
|
BlobSource blobref.StreamingFetcher
|
2011-11-02 01:37:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ blobserver.Storage = (*Index)(nil)
|
|
|
|
var _ search.Index = (*Index)(nil)
|
|
|
|
|
2013-01-14 04:19:36 +00:00
|
|
|
func New(s Storage) *Index {
|
2011-11-02 01:37:27 +00:00
|
|
|
return &Index{
|
|
|
|
s: s,
|
2011-11-07 16:40:31 +00:00
|
|
|
SimpleBlobHubPartitionMap: &blobserver.SimpleBlobHubPartitionMap{},
|
2011-11-02 01:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 22:33:10 +00:00
|
|
|
type prefixIter struct {
|
|
|
|
Iterator
|
|
|
|
prefix string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *prefixIter) Next() bool {
|
|
|
|
v := p.Iterator.Next()
|
|
|
|
if v && !strings.HasPrefix(p.Key(), p.prefix) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *Index) queryPrefix(key *keyType, args ...interface{}) *prefixIter {
|
|
|
|
return x.queryPrefixString(key.Prefix(args...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *Index) queryPrefixString(prefix string) *prefixIter {
|
|
|
|
return &prefixIter{
|
|
|
|
prefix: prefix,
|
|
|
|
Iterator: x.s.Find(prefix),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func closeIterator(it Iterator, perr *error) {
|
2011-12-03 19:26:42 +00:00
|
|
|
err := it.Close()
|
|
|
|
if err != nil && *perr == nil {
|
|
|
|
*perr = err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 14:16:00 +00:00
|
|
|
// isDeleted returns whether br (a blobref or a claim) should be considered deleted.
|
|
|
|
func (x *Index) isDeleted(br *blobref.BlobRef) bool {
|
|
|
|
var err error
|
|
|
|
it := x.queryPrefix(keyDeleted, br)
|
|
|
|
defer closeIterator(it, &err)
|
|
|
|
for it.Next() {
|
|
|
|
// parts are ["deleted", br.String(), blobref-of-delete-claim].
|
|
|
|
// see keyDeleted in keys.go
|
|
|
|
parts := strings.SplitN(it.Key(), "|", 3)
|
|
|
|
if len(parts) != 3 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
delClaimRef := blobref.Parse(parts[2])
|
|
|
|
if delClaimRef == nil {
|
|
|
|
panic(fmt.Errorf("invalid deleted claim for %v", parts[1]))
|
|
|
|
}
|
|
|
|
// The recursive call on the blobref of the delete claim
|
|
|
|
// checks that the claim itself was not deleted, in which case
|
|
|
|
// br is not considered deleted anymore.
|
|
|
|
// TODO(mpl): Each delete and undo delete adds a level of
|
|
|
|
// recursion so this could recurse far. is there a way to
|
|
|
|
// go faster in a worst case scenario?
|
|
|
|
return !x.isDeleted(delClaimRef)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func (x *Index) GetRecentPermanodes(dest chan *search.Result, owner *blobref.BlobRef, limit int) (err error) {
|
2011-11-02 01:37:27 +00:00
|
|
|
defer close(dest)
|
2011-11-29 19:19:32 +00:00
|
|
|
|
|
|
|
keyId, err := x.keyId(owner)
|
|
|
|
if err == ErrNotFound {
|
2013-01-09 22:21:32 +00:00
|
|
|
log.Printf("No recent permanodes because keyId for owner %v not found", owner)
|
2011-11-29 19:19:32 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err != nil {
|
2013-01-09 22:21:32 +00:00
|
|
|
log.Printf("Error fetching keyId for owner %v: %v", owner, err)
|
2011-11-29 19:19:32 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sent := 0
|
|
|
|
var seenPermanode dupSkipper
|
2011-11-29 22:33:10 +00:00
|
|
|
|
|
|
|
it := x.queryPrefix(keyRecentPermanode, keyId)
|
2011-12-03 19:26:42 +00:00
|
|
|
defer closeIterator(it, &err)
|
2011-11-29 19:19:32 +00:00
|
|
|
for it.Next() {
|
|
|
|
permaStr := it.Value()
|
|
|
|
parts := strings.SplitN(it.Key(), "|", 4)
|
|
|
|
if len(parts) != 4 {
|
|
|
|
continue
|
|
|
|
}
|
2012-05-13 20:27:11 +00:00
|
|
|
var mTimeSec int64
|
|
|
|
if mTime, err := time.Parse(time.RFC3339, unreverseTimeString(parts[2])); err == nil {
|
|
|
|
mTimeSec = mTime.Unix()
|
|
|
|
}
|
2011-11-29 19:19:32 +00:00
|
|
|
permaRef := blobref.Parse(permaStr)
|
|
|
|
if permaRef == nil {
|
|
|
|
continue
|
|
|
|
}
|
2012-10-08 14:16:00 +00:00
|
|
|
if x.isDeleted(permaRef) {
|
|
|
|
continue
|
|
|
|
}
|
2011-11-29 19:19:32 +00:00
|
|
|
if seenPermanode.Dup(permaStr) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dest <- &search.Result{
|
|
|
|
BlobRef: permaRef,
|
|
|
|
Signer: owner, // TODO(bradfitz): kinda. usually. for now.
|
|
|
|
LastModTime: mTimeSec,
|
|
|
|
}
|
|
|
|
sent++
|
|
|
|
if sent == limit {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2011-11-02 01:37:27 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
func (x *Index) GetOwnerClaims(permaNode, owner *blobref.BlobRef) (cl search.ClaimList, err error) {
|
2011-11-29 20:40:33 +00:00
|
|
|
keyId, err := x.keyId(owner)
|
|
|
|
if err == ErrNotFound {
|
|
|
|
err = nil
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
prefix := pipes("claim", permaNode, keyId, "")
|
2011-11-29 22:33:10 +00:00
|
|
|
it := x.queryPrefixString(prefix)
|
2011-12-03 19:26:42 +00:00
|
|
|
defer closeIterator(it, &err)
|
2011-11-29 20:40:33 +00:00
|
|
|
for it.Next() {
|
|
|
|
keyPart := strings.Split(it.Key(), "|")
|
|
|
|
valPart := strings.Split(it.Value(), "|")
|
|
|
|
if len(keyPart) < 5 || len(valPart) < 3 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
claimRef := blobref.Parse(keyPart[4])
|
|
|
|
if claimRef == nil {
|
|
|
|
continue
|
|
|
|
}
|
2012-05-13 20:27:11 +00:00
|
|
|
date, _ := time.Parse(time.RFC3339, keyPart[3])
|
2011-11-29 20:40:33 +00:00
|
|
|
cl = append(cl, &search.Claim{
|
|
|
|
BlobRef: claimRef,
|
|
|
|
Signer: owner,
|
|
|
|
Permanode: permaNode,
|
2012-05-13 20:27:11 +00:00
|
|
|
Date: date,
|
2011-11-29 20:40:33 +00:00
|
|
|
Type: urld(valPart[0]),
|
|
|
|
Attr: urld(valPart[1]),
|
|
|
|
Value: urld(valPart[2]),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return
|
2011-11-02 01:37:27 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
func (x *Index) GetBlobMimeType(blob *blobref.BlobRef) (mime string, size int64, err error) {
|
2013-01-09 03:43:09 +00:00
|
|
|
key := "meta:" + blob.String()
|
|
|
|
meta, err := x.s.Get(key)
|
2011-11-29 19:40:15 +00:00
|
|
|
if err == ErrNotFound {
|
2012-02-20 12:32:46 +00:00
|
|
|
err = os.ErrNotExist
|
2011-11-29 19:40:15 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
pos := strings.Index(meta, "|")
|
2013-01-09 03:43:09 +00:00
|
|
|
if pos < 0 {
|
|
|
|
panic(fmt.Sprintf("Bogus index row for key %q: got value %q", key, meta))
|
|
|
|
}
|
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
|
|
|
size, _ = strconv.ParseInt(meta[:pos], 10, 64)
|
2011-11-29 19:40:15 +00:00
|
|
|
mime = meta[pos+1:]
|
2011-11-02 01:37:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-11-28 03:29:23 +00:00
|
|
|
// maps from blobref of openpgp ascii-armored public key => gpg keyid like "2931A67C26F5ABDA"
|
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
|
|
|
func (x *Index) keyId(signer *blobref.BlobRef) (string, error) {
|
2011-11-28 03:29:23 +00:00
|
|
|
return x.s.Get("signerkeyid:" + signer.String())
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func (x *Index) PermanodeOfSignerAttrValue(signer *blobref.BlobRef, attr, val string) (permaNode *blobref.BlobRef, err error) {
|
2011-11-28 03:29:23 +00:00
|
|
|
keyId, err := x.keyId(signer)
|
2011-11-29 19:19:32 +00:00
|
|
|
if err == ErrNotFound {
|
2012-02-20 12:32:46 +00:00
|
|
|
return nil, os.ErrNotExist
|
2011-11-28 03:29:23 +00:00
|
|
|
}
|
2011-11-29 19:19:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2011-12-04 22:47:05 +00:00
|
|
|
it := x.queryPrefix(keySignerAttrValue, keyId, attr, val)
|
2011-12-03 19:26:42 +00:00
|
|
|
defer closeIterator(it, &err)
|
2011-11-28 03:29:23 +00:00
|
|
|
if it.Next() {
|
2012-10-08 14:16:00 +00:00
|
|
|
permaRef := blobref.Parse(it.Value())
|
|
|
|
if permaRef != nil && !x.isDeleted(permaRef) {
|
|
|
|
return permaRef, nil
|
|
|
|
}
|
2011-11-28 03:29:23 +00:00
|
|
|
}
|
2012-02-20 12:32:46 +00:00
|
|
|
return nil, os.ErrNotExist
|
2011-11-02 01:37:27 +00:00
|
|
|
}
|
|
|
|
|
2011-12-04 22:47:05 +00:00
|
|
|
// This is just like PermanodeOfSignerAttrValue except we return multiple and dup-suppress.
|
2012-11-13 23:02:12 +00:00
|
|
|
// If request.Query is "", it is not used in the prefix search.
|
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
|
|
|
func (x *Index) SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef, request *search.PermanodeByAttrRequest) (err error) {
|
2011-12-04 22:47:05 +00:00
|
|
|
defer close(dest)
|
|
|
|
if request.FuzzyMatch {
|
|
|
|
// TODO(bradfitz): remove this for now? figure out how to handle it generically?
|
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
|
|
|
return errors.New("TODO: SearchPermanodesWithAttr: generic indexer doesn't support FuzzyMatch on PermanodeByAttrRequest")
|
2011-12-04 22:47:05 +00:00
|
|
|
}
|
|
|
|
if request.Attribute == "" {
|
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
|
|
|
return errors.New("index: missing Attribute in SearchPermanodesWithAttr")
|
2011-12-04 22:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
keyId, err := x.keyId(request.Signer)
|
|
|
|
if err == ErrNotFound {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
seen := make(map[string]bool)
|
2012-11-13 23:02:12 +00:00
|
|
|
var it *prefixIter
|
|
|
|
if request.Query == "" {
|
|
|
|
it = x.queryPrefix(keySignerAttrValue, keyId, request.Attribute)
|
|
|
|
} else {
|
|
|
|
it = x.queryPrefix(keySignerAttrValue, keyId, request.Attribute, request.Query)
|
|
|
|
}
|
2011-12-04 22:47:05 +00:00
|
|
|
defer closeIterator(it, &err)
|
|
|
|
for it.Next() {
|
|
|
|
pn := blobref.Parse(it.Value())
|
|
|
|
if pn == nil {
|
|
|
|
continue
|
|
|
|
}
|
2012-10-08 14:16:00 +00:00
|
|
|
if x.isDeleted(pn) {
|
|
|
|
continue
|
|
|
|
}
|
2011-12-04 22:47:05 +00:00
|
|
|
pnstr := pn.String()
|
|
|
|
if seen[pnstr] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
seen[pnstr] = true
|
|
|
|
|
|
|
|
dest <- pn
|
|
|
|
if len(seen) == request.MaxResults {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func (x *Index) PathsOfSignerTarget(signer, target *blobref.BlobRef) (paths []*search.Path, err error) {
|
2011-12-01 18:43:57 +00:00
|
|
|
paths = []*search.Path{}
|
|
|
|
keyId, err := x.keyId(signer)
|
|
|
|
if err != nil {
|
|
|
|
if err == ErrNotFound {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
mostRecent := make(map[string]*search.Path)
|
|
|
|
maxClaimDates := make(map[string]string)
|
|
|
|
|
2011-12-02 02:06:25 +00:00
|
|
|
it := x.queryPrefix(keyPathBackward, keyId, target)
|
2011-12-03 19:26:42 +00:00
|
|
|
defer closeIterator(it, &err)
|
2011-12-01 18:43:57 +00:00
|
|
|
for it.Next() {
|
2011-12-02 01:28:32 +00:00
|
|
|
keyPart := strings.Split(it.Key(), "|")[1:]
|
2011-12-01 18:43:57 +00:00
|
|
|
valPart := strings.Split(it.Value(), "|")
|
|
|
|
if len(keyPart) < 3 || len(valPart) < 4 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
claimRef := blobref.Parse(keyPart[2])
|
|
|
|
baseRef := blobref.Parse(valPart[1])
|
|
|
|
if claimRef == nil || baseRef == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
claimDate := valPart[0]
|
|
|
|
active := valPart[2]
|
|
|
|
suffix := urld(valPart[3])
|
|
|
|
key := baseRef.String() + "/" + suffix
|
|
|
|
|
|
|
|
if claimDate > maxClaimDates[key] {
|
|
|
|
maxClaimDates[key] = claimDate
|
|
|
|
if active == "Y" {
|
|
|
|
mostRecent[key] = &search.Path{
|
|
|
|
Claim: claimRef,
|
|
|
|
ClaimDate: claimDate,
|
|
|
|
Base: baseRef,
|
|
|
|
Suffix: suffix,
|
2011-12-02 01:28:32 +00:00
|
|
|
Target: target,
|
2011-12-01 18:43:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
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
|
|
|
delete(mostRecent, key)
|
2011-12-01 18:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, v := range mostRecent {
|
|
|
|
paths = append(paths, v)
|
|
|
|
}
|
|
|
|
return paths, nil
|
2011-11-02 01:37:27 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
func (x *Index) PathsLookup(signer, base *blobref.BlobRef, suffix string) (paths []*search.Path, err error) {
|
2011-12-02 02:06:25 +00:00
|
|
|
paths = []*search.Path{}
|
|
|
|
keyId, err := x.keyId(signer)
|
|
|
|
if err != nil {
|
|
|
|
if err == ErrNotFound {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
it := x.queryPrefix(keyPathForward, keyId, base, suffix)
|
2011-12-03 19:26:42 +00:00
|
|
|
defer closeIterator(it, &err)
|
2011-12-02 02:06:25 +00:00
|
|
|
for it.Next() {
|
|
|
|
keyPart := strings.Split(it.Key(), "|")[1:]
|
|
|
|
valPart := strings.Split(it.Value(), "|")
|
|
|
|
if len(keyPart) < 5 || len(valPart) < 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
claimRef := blobref.Parse(keyPart[4])
|
|
|
|
baseRef := blobref.Parse(keyPart[1])
|
|
|
|
if claimRef == nil || baseRef == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
claimDate := unreverseTimeString(keyPart[3])
|
|
|
|
suffix := urld(keyPart[2])
|
|
|
|
target := blobref.Parse(valPart[1])
|
|
|
|
|
|
|
|
// TODO(bradfitz): investigate what's up with deleted
|
|
|
|
// forward path claims here. Needs docs with the
|
|
|
|
// interface too, and tests.
|
|
|
|
active := valPart[0]
|
|
|
|
_ = active
|
|
|
|
|
|
|
|
path := &search.Path{
|
|
|
|
Claim: claimRef,
|
|
|
|
ClaimDate: claimDate,
|
|
|
|
Base: baseRef,
|
|
|
|
Suffix: suffix,
|
|
|
|
Target: target,
|
|
|
|
}
|
|
|
|
paths = append(paths, path)
|
|
|
|
}
|
|
|
|
return
|
2011-11-02 01:37:27 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
func (x *Index) PathLookup(signer, base *blobref.BlobRef, suffix string, at time.Time) (*search.Path, error) {
|
2011-12-02 02:06:25 +00:00
|
|
|
paths, err := x.PathsLookup(signer, base, suffix)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var (
|
|
|
|
newest = int64(0)
|
|
|
|
atSeconds = int64(0)
|
|
|
|
best *search.Path
|
|
|
|
)
|
2012-02-20 12:32:46 +00:00
|
|
|
|
|
|
|
if !at.IsZero() {
|
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
|
|
|
atSeconds = at.Unix()
|
2011-12-02 02:06:25 +00:00
|
|
|
}
|
2012-02-20 12:32:46 +00:00
|
|
|
|
2011-12-02 02:06:25 +00:00
|
|
|
for _, path := range paths {
|
2012-11-02 12:36:33 +00:00
|
|
|
t, err := time.Parse(time.RFC3339, path.ClaimDate)
|
2011-12-02 02:06:25 +00:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
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
|
|
|
secs := t.Unix()
|
2011-12-02 02:06:25 +00:00
|
|
|
if atSeconds != 0 && secs > atSeconds {
|
|
|
|
// Too new
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if newest > secs {
|
|
|
|
// Too old
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Just right
|
|
|
|
newest, best = secs, path
|
|
|
|
}
|
|
|
|
if best == nil {
|
2012-02-20 12:32:46 +00:00
|
|
|
return nil, os.ErrNotExist
|
2011-12-02 02:06:25 +00:00
|
|
|
}
|
|
|
|
return best, nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func (x *Index) ExistingFileSchemas(wholeRef *blobref.BlobRef) (schemaRefs []*blobref.BlobRef, err error) {
|
2011-12-03 19:26:42 +00:00
|
|
|
it := x.queryPrefix(keyWholeToFileRef, wholeRef)
|
|
|
|
defer closeIterator(it, &err)
|
|
|
|
for it.Next() {
|
|
|
|
keyPart := strings.Split(it.Key(), "|")[1:]
|
|
|
|
if len(keyPart) < 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ref := blobref.Parse(keyPart[1])
|
|
|
|
if ref != nil {
|
|
|
|
schemaRefs = append(schemaRefs, ref)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return schemaRefs, nil
|
2011-12-03 16:05:34 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
func (x *Index) GetFileInfo(fileRef *blobref.BlobRef) (*search.FileInfo, error) {
|
2011-12-03 21:56:05 +00:00
|
|
|
key := "fileinfo|" + fileRef.String()
|
|
|
|
v, err := x.s.Get(key)
|
|
|
|
if err == ErrNotFound {
|
2012-02-20 12:32:46 +00:00
|
|
|
return nil, os.ErrNotExist
|
2011-12-03 21:56:05 +00:00
|
|
|
}
|
|
|
|
valPart := strings.Split(v, "|")
|
|
|
|
if len(valPart) < 3 {
|
|
|
|
log.Printf("index: bogus key %q = %q", key, v)
|
2012-02-20 12:32:46 +00:00
|
|
|
return nil, os.ErrNotExist
|
2011-12-03 21:56:05 +00:00
|
|
|
}
|
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
|
|
|
size, err := strconv.ParseInt(valPart[0], 10, 64)
|
2011-12-03 21:56:05 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("index: bogus integer at position 0 in key %q = %q", key, v)
|
2012-02-20 12:32:46 +00:00
|
|
|
return nil, os.ErrNotExist
|
2011-12-03 21:56:05 +00:00
|
|
|
}
|
|
|
|
fi := &search.FileInfo{
|
|
|
|
Size: size,
|
|
|
|
FileName: urld(valPart[1]),
|
|
|
|
MimeType: urld(valPart[2]),
|
|
|
|
}
|
|
|
|
return fi, nil
|
2011-12-03 16:05:34 +00:00
|
|
|
}
|
2012-02-26 12:49:03 +00:00
|
|
|
|
2012-11-05 09:29:42 +00:00
|
|
|
func (x *Index) EdgesTo(ref *blobref.BlobRef, opts *search.EdgesToOpts) (edges []*search.Edge, err error) {
|
|
|
|
it := x.queryPrefix(keyEdgeBackward, ref)
|
|
|
|
defer closeIterator(it, &err)
|
|
|
|
permanodeParents := map[string]*blobref.BlobRef{} // blobref key => blobref set
|
|
|
|
for it.Next() {
|
|
|
|
keyPart := strings.Split(it.Key(), "|")[1:]
|
|
|
|
if len(keyPart) < 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
parent := keyPart[1]
|
|
|
|
parentRef := blobref.Parse(parent)
|
|
|
|
if parentRef == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
valPart := strings.Split(it.Value(), "|")
|
|
|
|
if len(valPart) < 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
parentType, parentName := valPart[0], valPart[1]
|
|
|
|
if parentType == "permanode" {
|
|
|
|
permanodeParents[parent] = parentRef
|
|
|
|
} else {
|
|
|
|
edges = append(edges, &search.Edge{
|
|
|
|
From: parentRef,
|
|
|
|
FromType: parentType,
|
|
|
|
FromTitle: parentName,
|
|
|
|
To: ref,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, parentRef := range permanodeParents {
|
|
|
|
edges = append(edges, &search.Edge{
|
2012-11-07 22:54:00 +00:00
|
|
|
From: parentRef,
|
|
|
|
FromType: "permanode",
|
|
|
|
To: ref,
|
|
|
|
})
|
2012-11-05 09:29:42 +00:00
|
|
|
}
|
|
|
|
return edges, nil
|
2012-11-03 15:08:37 +00:00
|
|
|
}
|
|
|
|
|
2013-01-14 04:19:36 +00:00
|
|
|
func (x *Index) Storage() Storage { return x.s }
|