mirror of
https://github.com/minio/minio.git
synced 2025-04-23 11:55:47 -04:00
Code cleanup - simplify server side code. (#3870)
Fix all the issues reported by `gosimple` tool.
This commit is contained in:
parent
433225ab0d
commit
47ac410ab0
@ -1184,7 +1184,7 @@ func TestSetConfigHandler(t *testing.T) {
|
|||||||
t.Fatalf("Failed to decode set config result json %v", err)
|
t.Fatalf("Failed to decode set config result json %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.Status != true {
|
if !result.Status {
|
||||||
t.Error("Expected set-config to succeed, but failed")
|
t.Error("Expected set-config to succeed, but failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,10 +86,7 @@ func isBucketActionAllowed(action, bucket, prefix string) bool {
|
|||||||
resource := bucketARNPrefix + path.Join(bucket, prefix)
|
resource := bucketARNPrefix + path.Join(bucket, prefix)
|
||||||
var conditionKeyMap map[string]set.StringSet
|
var conditionKeyMap map[string]set.StringSet
|
||||||
// Validate action, resource and conditions with current policy statements.
|
// Validate action, resource and conditions with current policy statements.
|
||||||
if !bucketPolicyEvalStatements(action, resource, conditionKeyMap, policy.Statements) {
|
return bucketPolicyEvalStatements(action, resource, conditionKeyMap, policy.Statements)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBucketLocationHandler - GET Bucket location.
|
// GetBucketLocationHandler - GET Bucket location.
|
||||||
|
@ -209,10 +209,7 @@ func writeNotification(w http.ResponseWriter, notification map[string][]Notifica
|
|||||||
_, err = w.Write(append(notificationBytes, crlf...))
|
_, err = w.Write(append(notificationBytes, crlf...))
|
||||||
// Make sure we have flushed, this would set Transfer-Encoding: chunked.
|
// Make sure we have flushed, this would set Transfer-Encoding: chunked.
|
||||||
w.(http.Flusher).Flush()
|
w.(http.Flusher).Flush()
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CRLF character used for chunked transfer in accordance with HTTP standards.
|
// CRLF character used for chunked transfer in accordance with HTTP standards.
|
||||||
|
@ -213,9 +213,7 @@ func genFormatXLInvalidDisksOrder() []*formatConfigV1 {
|
|||||||
}
|
}
|
||||||
// Re order jbod for failure case.
|
// Re order jbod for failure case.
|
||||||
var jbod1 = make([]string, 8)
|
var jbod1 = make([]string, 8)
|
||||||
for i, j := range jbod {
|
copy(jbod1, jbod)
|
||||||
jbod1[i] = j
|
|
||||||
}
|
|
||||||
jbod1[1], jbod1[2] = jbod[2], jbod[1]
|
jbod1[1], jbod1[2] = jbod[2], jbod[1]
|
||||||
formatConfigs[2].XL.JBOD = jbod1
|
formatConfigs[2].XL.JBOD = jbod1
|
||||||
return formatConfigs
|
return formatConfigs
|
||||||
@ -576,9 +574,7 @@ func TestSavedUUIDOrder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// Re order jbod for failure case.
|
// Re order jbod for failure case.
|
||||||
var jbod1 = make([]string, 8)
|
var jbod1 = make([]string, 8)
|
||||||
for i, j := range jbod {
|
copy(jbod1, jbod)
|
||||||
jbod1[i] = j
|
|
||||||
}
|
|
||||||
jbod1[1], jbod1[2] = jbod[2], jbod[1]
|
jbod1[1], jbod1[2] = jbod[2], jbod[1]
|
||||||
formatConfigs[2].XL.JBOD = jbod1
|
formatConfigs[2].XL.JBOD = jbod1
|
||||||
uuidTestCases[1].shouldPass = false
|
uuidTestCases[1].shouldPass = false
|
||||||
|
@ -238,12 +238,9 @@ func saveFormatFS(formatPath string, fsFormat *formatConfigV1) error {
|
|||||||
}
|
}
|
||||||
defer lk.Close()
|
defer lk.Close()
|
||||||
|
|
||||||
if _, err = lk.Write(metadataBytes); err != nil {
|
_, err = lk.Write(metadataBytes)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success.
|
// Success.
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return if the part info in uploadedParts and completeParts are same.
|
// Return if the part info in uploadedParts and completeParts are same.
|
||||||
|
@ -67,12 +67,7 @@ func initMetaVolumeFS(fsPath, fsUUID string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
metaMultipartPath := pathJoin(fsPath, minioMetaMultipartBucket)
|
metaMultipartPath := pathJoin(fsPath, minioMetaMultipartBucket)
|
||||||
if err := mkdirAll(metaMultipartPath, 0777); err != nil {
|
return mkdirAll(metaMultipartPath, 0777)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return success here.
|
|
||||||
return nil
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,10 +98,7 @@ func isWebhookQueue(sqsArn arnSQS) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
rNotify := serverConfig.Notify.GetWebhookByID(sqsArn.AccountID)
|
rNotify := serverConfig.Notify.GetWebhookByID(sqsArn.AccountID)
|
||||||
if !rNotify.Enable {
|
return rNotify.Enable
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if queueArn is for an Redis queue.
|
// Returns true if queueArn is for an Redis queue.
|
||||||
|
@ -134,10 +134,7 @@ func isLocalStorage(ep *url.URL) bool {
|
|||||||
if globalMinioHost != "" && globalMinioPort != "" {
|
if globalMinioHost != "" && globalMinioPort != "" {
|
||||||
// if --address host:port was specified for distXL we short
|
// if --address host:port was specified for distXL we short
|
||||||
// circuit only the endPoint that matches host:port
|
// circuit only the endPoint that matches host:port
|
||||||
if net.JoinHostPort(globalMinioHost, globalMinioPort) == ep.Host {
|
return net.JoinHostPort(globalMinioHost, globalMinioPort) == ep.Host
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
// Split host to extract host information.
|
// Split host to extract host information.
|
||||||
host, _, err := net.SplitHostPort(ep.Host)
|
host, _, err := net.SplitHostPort(ep.Host)
|
||||||
|
@ -243,7 +243,7 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
|
|||||||
if len(result.Objects) != 0 {
|
if len(result.Objects) != 0 {
|
||||||
c.Errorf("%s: Number of objects in the result different from expected value.", instanceType)
|
c.Errorf("%s: Number of objects in the result different from expected value.", instanceType)
|
||||||
}
|
}
|
||||||
if result.IsTruncated != false {
|
if result.IsTruncated {
|
||||||
c.Errorf("%s: Expected IsTruncated to be `false`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
c.Errorf("%s: Expected IsTruncated to be `false`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
|
|||||||
if len(result.Objects) != i+1 {
|
if len(result.Objects) != i+1 {
|
||||||
c.Errorf("%s: Expected length of objects to be %d, instead found to be %d", instanceType, len(result.Objects), i+1)
|
c.Errorf("%s: Expected length of objects to be %d, instead found to be %d", instanceType, len(result.Objects), i+1)
|
||||||
}
|
}
|
||||||
if result.IsTruncated != false {
|
if result.IsTruncated {
|
||||||
c.Errorf("%s: Expected IsTruncated to be `false`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
c.Errorf("%s: Expected IsTruncated to be `false`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,7 +282,7 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
|
|||||||
if len(result.Objects) != 5 {
|
if len(result.Objects) != 5 {
|
||||||
c.Errorf("%s: Expected length of objects to be %d, instead found to be %d", instanceType, 5, len(result.Objects))
|
c.Errorf("%s: Expected length of objects to be %d, instead found to be %d", instanceType, 5, len(result.Objects))
|
||||||
}
|
}
|
||||||
if result.IsTruncated != true {
|
if !result.IsTruncated {
|
||||||
c.Errorf("%s: Expected IsTruncated to be `true`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
c.Errorf("%s: Expected IsTruncated to be `true`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -683,7 +683,7 @@ func testListObjectsTestsForNonExistantBucket(obj ObjectLayer, instanceType stri
|
|||||||
if len(result.Objects) != 0 {
|
if len(result.Objects) != 0 {
|
||||||
c.Fatalf("%s: Expected number of objects in the result to be `%d`, but instead found `%d`", instanceType, 0, len(result.Objects))
|
c.Fatalf("%s: Expected number of objects in the result to be `%d`, but instead found `%d`", instanceType, 0, len(result.Objects))
|
||||||
}
|
}
|
||||||
if result.IsTruncated != false {
|
if result.IsTruncated {
|
||||||
c.Fatalf("%s: Expected IsTruncated to be `false`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
c.Fatalf("%s: Expected IsTruncated to be `false`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
||||||
}
|
}
|
||||||
if err.Error() != "Bucket not found: bucket" {
|
if err.Error() != "Bucket not found: bucket" {
|
||||||
|
@ -569,7 +569,7 @@ func TestDoesV4PresignParamsExist(t *testing.T) {
|
|||||||
func TestParsePreSignV4(t *testing.T) {
|
func TestParsePreSignV4(t *testing.T) {
|
||||||
// converts the duration in seconds into string format.
|
// converts the duration in seconds into string format.
|
||||||
getDurationStr := func(expires int) string {
|
getDurationStr := func(expires int) string {
|
||||||
return strconv.FormatInt(int64(expires), 10)
|
return strconv.Itoa(expires)
|
||||||
}
|
}
|
||||||
// used in expected preSignValues, preSignValues.Date is of type time.Time .
|
// used in expected preSignValues, preSignValues.Date is of type time.Time .
|
||||||
queryTime := time.Now().UTC()
|
queryTime := time.Now().UTC()
|
||||||
|
@ -1690,9 +1690,7 @@ func removeDiskN(disks []string, n int) {
|
|||||||
// Makes a entire new copy of a StorageAPI slice.
|
// Makes a entire new copy of a StorageAPI slice.
|
||||||
func deepCopyStorageDisks(storageDisks []StorageAPI) []StorageAPI {
|
func deepCopyStorageDisks(storageDisks []StorageAPI) []StorageAPI {
|
||||||
newStorageDisks := make([]StorageAPI, len(storageDisks))
|
newStorageDisks := make([]StorageAPI, len(storageDisks))
|
||||||
for i, disk := range storageDisks {
|
copy(newStorageDisks, storageDisks)
|
||||||
newStorageDisks[i] = disk
|
|
||||||
}
|
|
||||||
return newStorageDisks
|
return newStorageDisks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,7 +696,7 @@ func testUploadWebHandler(obj ObjectLayer, instanceType string, t TestErrHandler
|
|||||||
t.Fatalf("Failed, %v", err)
|
t.Fatalf("Failed, %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(byteBuffer.Bytes(), content) != 0 {
|
if !bytes.Equal(byteBuffer.Bytes(), content) {
|
||||||
t.Fatalf("The upload file is different from the download file")
|
t.Fatalf("The upload file is different from the download file")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,7 +782,7 @@ func testDownloadWebHandler(obj ObjectLayer, instanceType string, t TestErrHandl
|
|||||||
t.Fatalf("Expected the response status to be 200, but instead found `%d`", code)
|
t.Fatalf("Expected the response status to be 200, but instead found `%d`", code)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(bodyContent, content) != 0 {
|
if !bytes.Equal(bodyContent, content) {
|
||||||
t.Fatalf("The downloaded file is corrupted")
|
t.Fatalf("The downloaded file is corrupted")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -805,7 +805,7 @@ func testDownloadWebHandler(obj ObjectLayer, instanceType string, t TestErrHandl
|
|||||||
t.Fatalf("Expected the response status to be 200, but instead found `%d`", code)
|
t.Fatalf("Expected the response status to be 200, but instead found `%d`", code)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(bodyContent, content) != 0 {
|
if !bytes.Equal(bodyContent, content) {
|
||||||
t.Fatalf("The downloaded file is corrupted")
|
t.Fatalf("The downloaded file is corrupted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ func (xl xlObjects) listObjectsHeal(bucket, prefix, marker, delimiter string, ma
|
|||||||
nextMarker = objInfo.Name
|
nextMarker = objInfo.Name
|
||||||
objInfos = append(objInfos, objInfo)
|
objInfos = append(objInfos, objInfo)
|
||||||
i++
|
i++
|
||||||
if walkResult.end == true {
|
if walkResult.end {
|
||||||
eof = true
|
eof = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -161,12 +161,7 @@ func newXLObjects(storageDisks []StorageAPI) (ObjectLayer, error) {
|
|||||||
xl.writeQuorum = writeQuorum
|
xl.writeQuorum = writeQuorum
|
||||||
|
|
||||||
// Do a quick heal on the buckets themselves for any discrepancies.
|
// Do a quick heal on the buckets themselves for any discrepancies.
|
||||||
if err := quickHeal(xl.storageDisks, xl.writeQuorum, xl.readQuorum); err != nil {
|
return xl, quickHeal(xl.storageDisks, xl.writeQuorum, xl.readQuorum)
|
||||||
return xl, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return successfully initialized object layer.
|
|
||||||
return xl, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown function for object storage interface.
|
// Shutdown function for object storage interface.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user