mirror of https://github.com/perkeep/perkeep.git
search/publich: rename PathLookup to PathsLookup, add PathLookup
Change-Id: If6804af2229885cfa22d67d608d17e600d7402f3
This commit is contained in:
parent
35d8e9ec2a
commit
d572f898f7
|
@ -397,7 +397,46 @@ func (mi *Indexer) PathsOfSignerTarget(signer, target *blobref.BlobRef) (paths [
|
|||
return paths, nil
|
||||
}
|
||||
|
||||
func (mi *Indexer) PathLookup(signer, base *blobref.BlobRef, suffix string) (paths []*search.Path, err os.Error) {
|
||||
func (mi *Indexer) PathLookup(signer, base *blobref.BlobRef, suffix string, at *time.Time) (*search.Path, os.Error) {
|
||||
// TODO: pass along the at time to a new helper function to
|
||||
// filter? maybe not worth it, since this list should be
|
||||
// small.
|
||||
paths, err := mi.PathsLookup(signer, base, suffix);
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
newest = int64(0)
|
||||
atSeconds = int64(0)
|
||||
best *search.Path
|
||||
)
|
||||
if at != nil {
|
||||
atSeconds = at.Seconds()
|
||||
}
|
||||
for _, path := range paths {
|
||||
t, err := time.Parse(time.RFC3339, trimRFC3339Subseconds(path.ClaimDate))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
secs := t.Seconds()
|
||||
if atSeconds != 0 && secs > atSeconds {
|
||||
// Too new
|
||||
continue
|
||||
}
|
||||
if newest > secs {
|
||||
// Too old
|
||||
continue
|
||||
}
|
||||
// Just right
|
||||
newest, best = secs, path
|
||||
}
|
||||
if best == nil {
|
||||
return nil, os.ENOENT
|
||||
}
|
||||
return best, nil
|
||||
}
|
||||
|
||||
func (mi *Indexer) PathsLookup(signer, base *blobref.BlobRef, suffix string) (paths []*search.Path, err os.Error) {
|
||||
keyId, err := mi.keyIdOfSigner(signer)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -96,5 +96,10 @@ type Index interface {
|
|||
|
||||
PathsOfSignerTarget(signer, target *blobref.BlobRef) ([]*Path, os.Error)
|
||||
|
||||
PathLookup(signer, base *blobref.BlobRef, suffix string) ([]*Path, os.Error)
|
||||
// All Path claims for (signer, base, suffix)
|
||||
PathsLookup(signer, base *blobref.BlobRef, suffix string) ([]*Path, os.Error)
|
||||
|
||||
// Most recent Path claim for (signer, base, suffix) as of
|
||||
// provided time 'at', or most recent if 'at' is nil.
|
||||
PathLookup(signer, base *blobref.BlobRef, suffix string, at *time.Time) (*Path, os.Error)
|
||||
}
|
||||
|
|
|
@ -111,14 +111,12 @@ func (pub *PublishHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
|
|||
|
||||
fmt.Fprintf(rw, "I am publish handler at base %q, serving root %q (permanode=%s), suffix %q<hr>",
|
||||
base, pub.RootName, pn, html.EscapeString(suffix))
|
||||
paths, err := pub.Search.Index().PathLookup(pub.Search.Owner(), pn, suffix)
|
||||
path, err := pub.Search.Index().PathLookup(pub.Search.Owner(), pn, suffix, nil)
|
||||
if err != nil {
|
||||
fmt.Fprintf(rw, "<b>Error:</b> %v", err)
|
||||
return
|
||||
}
|
||||
for _, path := range paths {
|
||||
fmt.Fprintf(rw, "<p><b>Target:</b> <a href='/ui/?p=%s'>%s</a></p>", path.Target, path.Target)
|
||||
}
|
||||
fmt.Fprintf(rw, "<p><b>Target:</b> <a href='/ui/?p=%s'>%s</a></p>", path.Target, path.Target)
|
||||
}
|
||||
|
||||
func (pub *PublishHandler) bootstrapPermanode(jsonSign *JSONSignHandler) os.Error {
|
||||
|
|
Loading…
Reference in New Issue