mirror of https://github.com/perkeep/perkeep.git
google cloud storage: support blobserver.Generationer
Change-Id: I9dd5bbaeb99e809bd4fff6f135d8141f4e1b051a
This commit is contained in:
parent
1d09bd4ebb
commit
f2f7b01160
|
@ -21,11 +21,13 @@ package cloudstorage
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"camlistore.org/pkg/blob"
|
||||
"camlistore.org/pkg/blobserver"
|
||||
|
@ -38,12 +40,24 @@ import (
|
|||
type Storage struct {
|
||||
bucket string // the gs bucket containing blobs
|
||||
client *googlestorage.Client
|
||||
|
||||
// For blobserver.Generationer:
|
||||
genTime time.Time
|
||||
genRandom string
|
||||
}
|
||||
|
||||
var _ blobserver.MaxEnumerateConfig = (*Storage)(nil)
|
||||
var (
|
||||
_ blobserver.MaxEnumerateConfig = (*Storage)(nil)
|
||||
_ blobserver.Generationer = (*Storage)(nil)
|
||||
)
|
||||
|
||||
func (gs *Storage) MaxEnumerate() int { return 1000 }
|
||||
|
||||
func (gs *Storage) StorageGeneration() (time.Time, string, error) {
|
||||
return gs.genTime, gs.genRandom, nil
|
||||
}
|
||||
func (gs *Storage) ResetStorageGeneration() error { return errors.New("not supported") }
|
||||
|
||||
func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (blobserver.Storage, error) {
|
||||
var (
|
||||
auth = config.RequiredObject("auth")
|
||||
|
@ -83,7 +97,10 @@ func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (blobserver.Stora
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("error statting bucket %q: %v", bucket, err)
|
||||
}
|
||||
log.Printf("Bucket info: %#v", bi)
|
||||
hash := sha1.New()
|
||||
fmt.Fprintf(hash, "%v%v", bi.TimeCreated, bi.Metageneration)
|
||||
gs.genRandom = fmt.Sprintf("%x", hash.Sum(nil))
|
||||
gs.genTime, _ = time.Parse(time.RFC3339, bi.TimeCreated)
|
||||
|
||||
return gs, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue