From 418921de89df94137ddae8c4b7bcf4756fcdfced Mon Sep 17 00:00:00 2001 From: Mohit Agarwal Date: Tue, 16 Aug 2016 20:27:14 +0530 Subject: [PATCH] minor cleanup - Reused contains() from utils.go at a couple of places - Cleanup in return statements and boolean checks --- cmd/auth-handler.go | 20 ++++++++------------ cmd/erasure-readfile_test.go | 2 +- cmd/object-handlers.go | 4 +--- cmd/posix.go | 6 ++---- cmd/rpc-server.go | 12 ++---------- cmd/server-rlimit-nix.go | 10 +--------- cmd/xl-v1-list-objects.go | 2 +- cmd/xl-v1-metadata.go | 5 ++--- cmd/xl-v1.go | 8 +------- dist/linux-systemd/readme.md | 2 +- 10 files changed, 20 insertions(+), 51 deletions(-) diff --git a/cmd/auth-handler.go b/cmd/auth-handler.go index 19e63064f..a428c929c 100644 --- a/cmd/auth-handler.go +++ b/cmd/auth-handler.go @@ -165,22 +165,18 @@ func setAuthHandler(h http.Handler) http.Handler { } // List of all support S3 auth types. -var supportedS3AuthTypes = []authType{ - authTypeAnonymous, - authTypePresigned, - authTypeSigned, - authTypePostPolicy, - authTypeStreamingSigned, +var supportedS3AuthTypes = map[authType]struct{}{ + authTypeAnonymous: {}, + authTypePresigned: {}, + authTypeSigned: {}, + authTypePostPolicy: {}, + authTypeStreamingSigned: {}, } // Validate if the authType is valid and supported. func isSupportedS3AuthType(aType authType) bool { - for _, a := range supportedS3AuthTypes { - if a == aType { - return true - } - } - return false + _, ok := supportedS3AuthTypes[aType] + return ok } // handler for validating incoming authorization headers. diff --git a/cmd/erasure-readfile_test.go b/cmd/erasure-readfile_test.go index 3a6d5c3ca..7e2a6fb7b 100644 --- a/cmd/erasure-readfile_test.go +++ b/cmd/erasure-readfile_test.go @@ -112,7 +112,7 @@ func testGetReadDisks(t *testing.T, xl xlObjects) { t.Errorf("test-case %d - expected nextIndex: %d, got : %d", i+1, test.nextIndex, nextIndex) continue } - if reflect.DeepEqual(test.retDisks, disks) == false { + if !reflect.DeepEqual(test.retDisks, disks) { t.Errorf("test-case %d : incorrect disks returned. expected %+v, got %+v", i+1, test.retDisks, disks) continue } diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index 9d5230e79..019bb5d3a 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -268,9 +268,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re } // Skip the first element if it is '/', split the rest. - if strings.HasPrefix(objectSource, "/") { - objectSource = objectSource[1:] - } + objectSource = strings.TrimPrefix(objectSource, "/") splits := strings.SplitN(objectSource, "/", 2) // Save sourceBucket and sourceObject extracted from url Path. diff --git a/cmd/posix.go b/cmd/posix.go index cfc902196..29f8c93ce 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -107,10 +107,8 @@ func newPosix(diskPath string) (StorageAPI, error) { if err != nil { if os.IsNotExist(err) { // Disk not found create it. - if err = os.MkdirAll(diskPath, 0777); err != nil { - return fs, err - } - return fs, nil + err = os.MkdirAll(diskPath, 0777) + return fs, err } return fs, err } diff --git a/cmd/rpc-server.go b/cmd/rpc-server.go index f57b175e1..2a32705d1 100644 --- a/cmd/rpc-server.go +++ b/cmd/rpc-server.go @@ -16,11 +16,7 @@ type storageServer struct { // MakeVolHandler - make vol handler is rpc wrapper for MakeVol operation. func (s *storageServer) MakeVolHandler(arg *string, reply *GenericReply) error { - err := s.storage.MakeVol(*arg) - if err != nil { - return err - } - return nil + return s.storage.MakeVol(*arg) } // ListVolsHandler - list vols handler is rpc wrapper for ListVols operation. @@ -46,11 +42,7 @@ func (s *storageServer) StatVolHandler(arg *string, reply *VolInfo) error { // DeleteVolHandler - delete vol handler is a rpc wrapper for // DeleteVol operation. func (s *storageServer) DeleteVolHandler(arg *string, reply *GenericReply) error { - err := s.storage.DeleteVol(*arg) - if err != nil { - return err - } - return nil + return s.storage.DeleteVol(*arg) } /// File operations diff --git a/cmd/server-rlimit-nix.go b/cmd/server-rlimit-nix.go index e3ed78beb..687d41e4b 100644 --- a/cmd/server-rlimit-nix.go +++ b/cmd/server-rlimit-nix.go @@ -37,15 +37,7 @@ func setMaxOpenFiles() error { // TO increase this limit further user has to manually edit // `/etc/security/limits.conf` rLimit.Cur = rLimit.Max - err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return err - } - err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return err - } - return nil + return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) } // Set max memory used by minio as a process, this value is usually diff --git a/cmd/xl-v1-list-objects.go b/cmd/xl-v1-list-objects.go index 2cac2943c..6aa4bc7a2 100644 --- a/cmd/xl-v1-list-objects.go +++ b/cmd/xl-v1-list-objects.go @@ -76,7 +76,7 @@ func (xl xlObjects) listObjects(bucket, prefix, marker, delimiter string, maxKey nextMarker = objInfo.Name objInfos = append(objInfos, objInfo) i++ - if walkResult.end == true { + if walkResult.end { eof = true break } diff --git a/cmd/xl-v1-metadata.go b/cmd/xl-v1-metadata.go index fbdd7f129..8e2b04c5e 100644 --- a/cmd/xl-v1-metadata.go +++ b/cmd/xl-v1-metadata.go @@ -137,11 +137,10 @@ func (m xlMetaV1) IsValid() bool { } // ObjectPartIndex - returns the index of matching object part number. -func (m xlMetaV1) ObjectPartIndex(partNumber int) (index int) { +func (m xlMetaV1) ObjectPartIndex(partNumber int) int { for i, part := range m.Parts { if partNumber == part.Number { - index = i - return index + return i } } return -1 diff --git a/cmd/xl-v1.go b/cmd/xl-v1.go index b7bfa1376..a83015b6e 100644 --- a/cmd/xl-v1.go +++ b/cmd/xl-v1.go @@ -95,13 +95,7 @@ func checkSufficientDisks(disks []string) error { // isDiskFound - validates if the disk is found in a list of input disks. func isDiskFound(disk string, disks []string) bool { - for _, d := range disks { - // Disk found return - if disk == d { - return true - } - } - return false + return contains(disks, disk) } // newXLObjects - initialize new xl object layer. diff --git a/dist/linux-systemd/readme.md b/dist/linux-systemd/readme.md index dc2447fac..8399b4582 100644 --- a/dist/linux-systemd/readme.md +++ b/dist/linux-systemd/readme.md @@ -26,7 +26,7 @@ EOT Put minio.service in /etc/systemd/system/ ``` -curl https://raw.githubusercontent.com/minio/minio/master/dist/linux-systemd/minio.service > /etc/systemd/system/ +( cd /etc/systemd/system/; curl -O https://raw.githubusercontent.com/minio/minio/master/dist/linux-systemd/minio.service ) ``` Enable startup on boot