diff --git a/lib/go/blobref/Makefile b/lib/go/blobref/Makefile index 2ac95f5bc..71fc93b5d 100644 --- a/lib/go/blobref/Makefile +++ b/lib/go/blobref/Makefile @@ -2,6 +2,7 @@ include $(GOROOT)/src/Make.inc TARG=camli/blobref GOFILES=\ - blobref.go + blobref.go\ + fetcher.go\ include $(GOROOT)/src/Make.pkg diff --git a/lib/go/blobref/blobref.go b/lib/go/blobref/blobref.go index 26ce0e5ff..269ce360d 100644 --- a/lib/go/blobref/blobref.go +++ b/lib/go/blobref/blobref.go @@ -5,7 +5,6 @@ import ( "fmt" "hash" "io" - "os" "regexp" ) @@ -28,10 +27,6 @@ type ReadSeekCloser interface { io.Closer } -type Fetcher interface { - Fetch(*BlobRef) (file ReadSeekCloser, size int64, err os.Error) -} - func (b *BlobRef) HashName() string { return b.hashName } diff --git a/lib/go/blobref/fetcher.go b/lib/go/blobref/fetcher.go new file mode 100644 index 000000000..7d9963a5a --- /dev/null +++ b/lib/go/blobref/fetcher.go @@ -0,0 +1,35 @@ +package blobref + +import ( + "fmt" + "os" +) + +type Fetcher interface { + Fetch(*BlobRef) (file ReadSeekCloser, size int64, err os.Error) +} + +func NewSimpleDirectoryFetcher(dir string) Fetcher { + return &dirFetcher{dir, "camli"} +} + +type dirFetcher struct { + directory, extension string +} + +func (df *dirFetcher) Fetch(b *BlobRef) (file ReadSeekCloser, size int64, err os.Error) { + fileName := fmt.Sprintf("%s/%s.%s", df.directory, b.String(), df.extension) + var stat *os.FileInfo + stat, err = os.Stat(fileName) + if err != nil { + return + } + file, err = os.Open(fileName, os.O_RDONLY, 0) + if err != nil { + return + } + size = stat.Size + return +} + + diff --git a/server/go/sigserver/camsigd.go b/server/go/sigserver/camsigd.go index a584f26c9..fb92aa417 100644 --- a/server/go/sigserver/camsigd.go +++ b/server/go/sigserver/camsigd.go @@ -16,27 +16,11 @@ var accessPassword string var flagPubKeyDir *string = flag.String("pubkey-dir", "test/pubkey-blobs", "Temporary development hack; directory to dig-xxxx.camli public keys.") -type pubkeyDirFetcher struct{} -func (_ *pubkeyDirFetcher) Fetch(b *blobref.BlobRef) (file blobref.ReadSeekCloser, size int64, err os.Error) { - fileName := fmt.Sprintf("%s/%s.camli", *flagPubKeyDir, b.String()) - var stat *os.FileInfo - stat, err = os.Stat(fileName) - if err != nil { - return - } - file, err = os.Open(fileName, os.O_RDONLY, 0) - if err != nil { - return - } - size = stat.Size - return -} - // TODO: for now, the only implementation of the blobref.Fetcher // interface for fetching public keys is the "local, from disk" // implementation used for testing. In reality we'd want to be able // to fetch these from blobservers. -var pubKeyFetcher = &pubkeyDirFetcher{} +var pubKeyFetcher = blobref.NewSimpleDirectoryFetcher(*flagPubKeyDir) func handleRoot(conn http.ResponseWriter, req *http.Request) { fmt.Fprintf(conn, "camsigd")