2011-04-04 02:59:46 +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 s3
|
|
|
|
|
|
|
|
import (
|
2013-08-22 00:05:52 +00:00
|
|
|
"fmt"
|
2013-08-31 21:29:15 +00:00
|
|
|
"os"
|
2013-08-22 00:05:52 +00:00
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
"camlistore.org/pkg/blob"
|
2013-09-12 15:04:10 +00:00
|
|
|
"camlistore.org/pkg/syncutil"
|
2011-04-04 02:59:46 +00:00
|
|
|
)
|
|
|
|
|
2013-09-12 15:04:10 +00:00
|
|
|
var statGate = syncutil.NewGate(20) // arbitrary
|
2013-08-22 00:05:52 +00:00
|
|
|
|
2014-03-17 02:39:43 +00:00
|
|
|
func (sto *s3Storage) StatBlobs(dest chan<- blob.SizedRef, blobs []blob.Ref) (err error) {
|
|
|
|
if faultStat.FailErr(&err) {
|
|
|
|
return
|
|
|
|
}
|
2013-10-05 07:43:15 +00:00
|
|
|
var wg syncutil.Group
|
2011-04-04 22:15:09 +00:00
|
|
|
for _, br := range blobs {
|
2013-10-11 05:54:23 +00:00
|
|
|
br := br
|
2013-08-22 00:05:52 +00:00
|
|
|
statGate.Start()
|
2013-10-05 07:43:15 +00:00
|
|
|
wg.Go(func() error {
|
2013-08-22 00:05:52 +00:00
|
|
|
defer statGate.Done()
|
2013-10-05 07:43:15 +00:00
|
|
|
|
2013-08-22 00:05:52 +00:00
|
|
|
size, err := sto.s3Client.Stat(br.String(), sto.bucket)
|
2013-10-05 07:43:15 +00:00
|
|
|
if err == nil {
|
2014-01-28 20:46:52 +00:00
|
|
|
dest <- blob.SizedRef{Ref: br, Size: uint32(size)}
|
2013-10-05 07:43:15 +00:00
|
|
|
return nil
|
2013-08-22 00:05:52 +00:00
|
|
|
}
|
2013-10-05 07:43:15 +00:00
|
|
|
if err == os.ErrNotExist {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return fmt.Errorf("error statting %v: %v", br, err)
|
|
|
|
})
|
2011-04-04 22:15:09 +00:00
|
|
|
}
|
2013-10-05 07:43:15 +00:00
|
|
|
return wg.Err()
|
2011-04-04 02:59:46 +00:00
|
|
|
}
|