Add comments

master
Harshavardhana 10 years ago
parent 721ec9ef5a
commit 137584d658
  1. 10
      buildscripts/deadcode.go
  2. 11
      pkg/storage/fs/fs.go
  3. 49
      pkg/storage/inmemory/inmemory.go
  4. 3
      pkg/utils/config/config_test.go
  5. 3
      pkg/utils/cpu/cpu.go
  6. 13
      pkg/utils/crypto/sha512/sha512.go
  7. 2
      pkg/utils/crypto/sha512/sha512_gen.go
  8. 1
      pkg/utils/crypto/x509/generator.go
  9. 50
      pkg/utils/helpers/common.go
  10. 1
      pkg/utils/policy/date.go

@ -118,15 +118,19 @@ func doPackage(fs *token.FileSet, pkg *ast.Package) {
} }
} }
case *ast.FuncDecl: case *ast.FuncDecl:
// Skip if function is 'main' // if function is 'main', never check
if n.Name.Name == "main" { if n.Name.Name == "main" {
continue continue
} }
// Skip non-exported functions // Do not be strict on non-exported functions
if !ast.IsExported(n.Name.Name) { if !ast.IsExported(n.Name.Name) {
continue continue
} }
// Check if comments are missing from exported functions // Do not be strict for field list functions
// if n.Recv != nil {
// continue
//}
// Be strict for global functions
_, ok := cmap[n] _, ok := cmap[n]
if ok == false { if ok == false {
p.missingcomments[n.Name.Name] = n p.missingcomments[n.Name.Name] = n

@ -58,6 +58,15 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error, s *storage) {
close(errorChannel) close(errorChannel)
} }
func appendUniq(slice []string, i string) []string {
for _, ele := range slice {
if ele == i {
return slice
}
}
return append(slice, i)
}
// Bucket Operations // Bucket Operations
func (storage *storage) ListBuckets() ([]mstorage.BucketMetadata, error) { func (storage *storage) ListBuckets() ([]mstorage.BucketMetadata, error) {
files, err := ioutil.ReadDir(storage.root) files, err := ioutil.ReadDir(storage.root)
@ -379,7 +388,7 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso
} }
metadataList = append(metadataList, metadata) metadataList = append(metadataList, metadata)
case delimited != "": case delimited != "":
resources.CommonPrefixes = helpers.AppendUniqStr(resources.CommonPrefixes, delimited) resources.CommonPrefixes = helpers.appendUniq(resources.CommonPrefixes, delimited)
} }
case resources.Delimiter != "" && strings.HasPrefix(name, resources.Prefix): case resources.Delimiter != "" && strings.HasPrefix(name, resources.Prefix):
delimited := delimiter(name, resources.Delimiter) delimited := delimiter(name, resources.Delimiter)

@ -47,6 +47,23 @@ type storedObject struct {
data []byte data []byte
} }
// Start inmemory object server
func Start() (chan<- string, <-chan error, *storage) {
ctrlChannel := make(chan string)
errorChannel := make(chan error)
go start(ctrlChannel, errorChannel)
return ctrlChannel, errorChannel, &storage{
bucketdata: make(map[string]storedBucket),
objectdata: make(map[string]storedObject),
lock: new(sync.RWMutex),
}
}
func start(ctrlChannel <-chan string, errorChannel chan<- error) {
close(errorChannel)
}
// GET object from memory buffer
func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error) { func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error) {
// TODO synchronize access // TODO synchronize access
// get object // get object
@ -60,14 +77,17 @@ func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object st
} }
} }
// Not implemented
func (storage *storage) StoreBucketPolicy(bucket string, policy interface{}) error { func (storage *storage) StoreBucketPolicy(bucket string, policy interface{}) error {
return mstorage.ApiNotImplemented{Api: "PutBucketPolicy"} return mstorage.ApiNotImplemented{Api: "PutBucketPolicy"}
} }
// Not implemented
func (storage *storage) GetBucketPolicy(bucket string) (interface{}, error) { func (storage *storage) GetBucketPolicy(bucket string) (interface{}, error) {
return policy.BucketPolicy{}, mstorage.ApiNotImplemented{Api: "GetBucketPolicy"} return policy.BucketPolicy{}, mstorage.ApiNotImplemented{Api: "GetBucketPolicy"}
} }
// PUT object to memory buffer
func (storage *storage) StoreObject(bucket, key, contentType string, data io.Reader) error { func (storage *storage) StoreObject(bucket, key, contentType string, data io.Reader) error {
storage.lock.Lock() storage.lock.Lock()
defer storage.lock.Unlock() defer storage.lock.Unlock()
@ -108,6 +128,7 @@ func (storage *storage) StoreObject(bucket, key, contentType string, data io.Rea
return nil return nil
} }
// Create Bucket in memory
func (storage *storage) StoreBucket(bucketName string) error { func (storage *storage) StoreBucket(bucketName string) error {
storage.lock.Lock() storage.lock.Lock()
defer storage.lock.Unlock() defer storage.lock.Unlock()
@ -128,11 +149,11 @@ func (storage *storage) StoreBucket(bucketName string) error {
return nil return nil
} }
// List objects in memory
func (storage *storage) ListObjects(bucket string, resources mstorage.BucketResourcesMetadata) ([]mstorage.ObjectMetadata, mstorage.BucketResourcesMetadata, error) { func (storage *storage) ListObjects(bucket string, resources mstorage.BucketResourcesMetadata) ([]mstorage.ObjectMetadata, mstorage.BucketResourcesMetadata, error) {
if _, ok := storage.bucketdata[bucket]; ok == false { if _, ok := storage.bucketdata[bucket]; ok == false {
return []mstorage.ObjectMetadata{}, mstorage.BucketResourcesMetadata{IsTruncated: false}, mstorage.BucketNotFound{Bucket: bucket} return []mstorage.ObjectMetadata{}, mstorage.BucketResourcesMetadata{IsTruncated: false}, mstorage.BucketNotFound{Bucket: bucket}
} }
// TODO prefix and count handling
var results []mstorage.ObjectMetadata var results []mstorage.ObjectMetadata
var keys []string var keys []string
for key := range storage.objectdata { for key := range storage.objectdata {
@ -157,10 +178,16 @@ func (storage *storage) ListObjects(bucket string, resources mstorage.BucketReso
type ByBucketName []mstorage.BucketMetadata type ByBucketName []mstorage.BucketMetadata
func (b ByBucketName) Len() int { return len(b) } // Len of bucket name
func (b ByBucketName) Swap(i, j int) { b[i], b[j] = b[j], b[i] } func (b ByBucketName) Len() int { return len(b) }
// Swap bucket i, j
func (b ByBucketName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
// Less
func (b ByBucketName) Less(i, j int) bool { return b[i].Name < b[j].Name } func (b ByBucketName) Less(i, j int) bool { return b[i].Name < b[j].Name }
// List buckets
func (storage *storage) ListBuckets() ([]mstorage.BucketMetadata, error) { func (storage *storage) ListBuckets() ([]mstorage.BucketMetadata, error) {
var results []mstorage.BucketMetadata var results []mstorage.BucketMetadata
for _, bucket := range storage.bucketdata { for _, bucket := range storage.bucketdata {
@ -170,21 +197,7 @@ func (storage *storage) ListBuckets() ([]mstorage.BucketMetadata, error) {
return results, nil return results, nil
} }
func Start() (chan<- string, <-chan error, *storage) { // HEAD object
ctrlChannel := make(chan string)
errorChannel := make(chan error)
go start(ctrlChannel, errorChannel)
return ctrlChannel, errorChannel, &storage{
bucketdata: make(map[string]storedBucket),
objectdata: make(map[string]storedObject),
lock: new(sync.RWMutex),
}
}
func start(ctrlChannel <-chan string, errorChannel chan<- error) {
close(errorChannel)
}
func (storage *storage) GetObjectMetadata(bucket, key string) (mstorage.ObjectMetadata, error) { func (storage *storage) GetObjectMetadata(bucket, key string) (mstorage.ObjectMetadata, error) {
objectKey := bucket + ":" + key objectKey := bucket + ":" + key

@ -23,7 +23,6 @@ import (
"testing" "testing"
"github.com/minio-io/minio/pkg/utils/crypto/keys" "github.com/minio-io/minio/pkg/utils/crypto/keys"
"github.com/minio-io/minio/pkg/utils/helpers"
. "gopkg.in/check.v1" . "gopkg.in/check.v1"
) )
@ -35,7 +34,7 @@ func Test(t *testing.T) { TestingT(t) }
func (s *MySuite) TestConfig(c *C) { func (s *MySuite) TestConfig(c *C) {
conf := Config{} conf := Config{}
conf.configPath, _ = helpers.MakeTempTestDir() conf.configPath, _ = ioutil.TempDir("/tmp", "minio-test-")
defer os.RemoveAll(conf.configPath) defer os.RemoveAll(conf.configPath)
conf.configFile = path.Join(conf.configPath, "config.json") conf.configFile = path.Join(conf.configPath, "config.json")
if _, err := os.Stat(conf.configFile); os.IsNotExist(err) { if _, err := os.Stat(conf.configFile); os.IsNotExist(err) {

@ -21,14 +21,17 @@ package cpu
// int has_avx2 (void); // int has_avx2 (void);
import "C" import "C"
// CPUID instruction verification wrapper for SSE41 extensions
func HasSSE41() bool { func HasSSE41() bool {
return int(C.has_sse41()) == 1 return int(C.has_sse41()) == 1
} }
// CPUID instruction verification wrapper for AVX extensions
func HasAVX() bool { func HasAVX() bool {
return int(C.has_avx()) == 1 return int(C.has_avx()) == 1
} }
// CPUID instruction verification wrapper for AVX2 extensions
func HasAVX2() bool { func HasAVX2() bool {
return int(C.has_avx2()) == 1 return int(C.has_avx2()) == 1
} }

@ -55,6 +55,7 @@ func block(dig *digest, p []byte) {
} }
} }
// Reset digest to its default value
func (d *digest) Reset() { func (d *digest) Reset() {
d.h[0] = init0 d.h[0] = init0
d.h[1] = init1 d.h[1] = init1
@ -75,12 +76,13 @@ func New() hash.Hash {
return d return d
} }
func (d *digest) Size() int { // Return output array byte size
return Size func (d *digest) Size() int { return Size }
}
// Return blockSize
func (d *digest) BlockSize() int { return BlockSize } func (d *digest) BlockSize() int { return BlockSize }
// Write blocks
func (d *digest) Write(p []byte) (nn int, err error) { func (d *digest) Write(p []byte) (nn int, err error) {
nn = len(p) nn = len(p)
d.len += uint64(nn) d.len += uint64(nn)
@ -104,6 +106,7 @@ func (d *digest) Write(p []byte) (nn int, err error) {
return return
} }
// Calculate sha512
func (d0 *digest) Sum(in []byte) []byte { func (d0 *digest) Sum(in []byte) []byte {
// Make a copy of d0 so that caller can keep writing and summing. // Make a copy of d0 so that caller can keep writing and summing.
d := new(digest) d := new(digest)
@ -112,6 +115,7 @@ func (d0 *digest) Sum(in []byte) []byte {
return append(in, hash[:]...) return append(in, hash[:]...)
} }
// internal checksum calculation, returns [Size]byte
func (d *digest) checkSum() [Size]byte { func (d *digest) checkSum() [Size]byte {
// Padding. Add a 1 bit and 0 bits until 112 bytes mod 128. // Padding. Add a 1 bit and 0 bits until 112 bytes mod 128.
len := d.len len := d.len
@ -153,6 +157,7 @@ func (d *digest) checkSum() [Size]byte {
// Convenience functions // Convenience functions
// Single caller function returns [Size]byte
func Sum512(data []byte) [Size]byte { func Sum512(data []byte) [Size]byte {
var d digest var d digest
d.Reset() d.Reset()
@ -160,6 +165,7 @@ func Sum512(data []byte) [Size]byte {
return d.checkSum() return d.checkSum()
} }
// Takes in io.Reader, low memory footprint checksum
func Sum(reader io.Reader) ([]byte, error) { func Sum(reader io.Reader) ([]byte, error) {
h := New() h := New()
var err error var err error
@ -176,6 +182,7 @@ func Sum(reader io.Reader) ([]byte, error) {
return h.Sum(nil), nil return h.Sum(nil), nil
} }
// Similar to 'Sum()' but returns a [Size]byte
func SumStream(reader io.Reader) ([Size]byte, error) { func SumStream(reader io.Reader) ([Size]byte, error) {
var returnValue [Size]byte var returnValue [Size]byte
sumSlice, err := Sum(reader) sumSlice, err := Sum(reader)

@ -29,6 +29,7 @@ import (
sha512intel "github.com/minio-io/minio/pkg/utils/crypto/sha512" sha512intel "github.com/minio-io/minio/pkg/utils/crypto/sha512"
) )
// Intels processor accelerated sha512 implementation
func SumIntel(reader io.Reader) ([]byte, error) { func SumIntel(reader io.Reader) ([]byte, error) {
h := sha512intel.New() h := sha512intel.New()
var err error var err error
@ -45,6 +46,7 @@ func SumIntel(reader io.Reader) ([]byte, error) {
return h.Sum(nil), nil return h.Sum(nil), nil
} }
// Golang default implementation
func Sum(reader io.Reader) ([]byte, error) { func Sum(reader io.Reader) ([]byte, error) {
k := sha512.New() k := sha512.New()
var err error var err error

@ -72,6 +72,7 @@ func pemBlockForKey(priv interface{}) *pem.Block {
} }
} }
// Generate certificates using custom parameters
func (tls *Certificates) GenerateCertificates(params X509Params) error { func (tls *Certificates) GenerateCertificates(params X509Params) error {
var rsaBits int = 2048 var rsaBits int = 2048
var priv interface{} var priv interface{}

@ -1,50 +0,0 @@
/*
* Mini Object Storage, (C) 2014 Minio, 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 helpers
import (
"io/ioutil"
"strings"
)
// Create a new temp directory
func MakeTempTestDir() (string, error) {
return ioutil.TempDir("/tmp", "minio-test-")
}
// Camelcase input string
func FirstUpper(str string) string {
return strings.ToUpper(str[0:1]) + str[1:]
}
func AppendUniqInt(slice []int, i int) []int {
for _, ele := range slice {
if ele == i {
return slice
}
}
return append(slice, i)
}
func AppendUniqStr(slice []string, i string) []string {
for _, ele := range slice {
if ele == i {
return slice
}
}
return append(slice, i)
}

@ -13,6 +13,7 @@ type Date struct {
Day byte Day byte
} }
// Date to string output in yyyy-mm-dd format
func (d Date) String() string { func (d Date) String() string {
return fmt.Sprintf("%04d-%02d-%02d", d.Year, d.Month, d.Day) return fmt.Sprintf("%04d-%02d-%02d", d.Year, d.Month, d.Day)
} }

Loading…
Cancel
Save