func retrieveBucket(lc types.LifeCycle) error {
	defaultConfig := false
	defaultDays := 0
	bucket, err := yig.MetaStorage.GetBucket(lc.BucketName, false)
	if err != nil {
		return err
	}
	rules := bucket.LC.Rule
	for _, rule := range rules {
		if rule.Prefix == "" {
			defaultConfig = true
			defaultDays, err = strconv.Atoi(rule.Expiration)
			if err != nil {
				return err
			}
		}
	}
	var request datatype.ListObjectsRequest
	request.Versioned = false
	request.MaxKeys = 1000
	if defaultConfig == true {
		for {
			retObjects, _, truncated, nextMarker, nextVerIdMarker, err := yig.ListObjectsInternal(bucket.Name, request)
			if err != nil {
				return err
			}

			for _, object := range retObjects {
				prefixMatch := false
				matchDays := 0
				for _, rule := range rules {
					if rule.Prefix == "" {
						continue
					}
					if strings.HasPrefix(object.Name, rule.Prefix) == false {
						continue
					}
					prefixMatch = true
					matchDays, err = strconv.Atoi(rule.Expiration)
					if err != nil {
						return err
					}
				}
				days := 0
				if prefixMatch == true {
					days = matchDays
				} else {
					days = defaultDays
				}
				helper.Debugln("inteval:", time.Since(object.LastModifiedTime).Seconds())
				if checkIfExpiration(object.LastModifiedTime, days) {
					helper.Debugln("come here")
					if object.NullVersion {
						object.VersionId = ""
					}
					_, err = yig.DeleteObject(object.BucketName, object.Name, object.VersionId, common.Credential{})
					if err != nil {
						helper.Logger.Println(5, "[FAILED]", object.BucketName, object.Name, object.VersionId, err)
						fmt.Println("[FAILED]", object.BucketName, object.Name, object.VersionId, err)
						continue
					}
					helper.Logger.Println(5, "[DELETED]", object.BucketName, object.Name, object.VersionId)
					fmt.Println("[DELETED]", object.BucketName, object.Name, object.VersionId)
				}
			}
			if truncated == true {
				request.KeyMarker = nextMarker
				request.VersionIdMarker = nextVerIdMarker
			} else {
				break
			}
		}
	} else {
		for _, rule := range rules {
			if rule.Prefix == "" {
				continue
			}
			days, _ := strconv.Atoi(rule.Expiration)
			if err != nil {
				return err
			}
			request.Prefix = rule.Prefix
			for {

				retObjects, _, truncated, nextMarker, nextVerIdMarker, err := yig.ListObjectsInternal(bucket.Name, request)
				if err != nil {
					return err
				}
				for _, object := range retObjects {
					if checkIfExpiration(object.LastModifiedTime, days) {
						_, err = yig.DeleteObject(object.BucketName, object.Name, object.VersionId, common.Credential{})
						if err != nil {
							logger.Println(5, "failed to delete object:", object.Name, object.BucketName)
							helper.Logger.Println(5, "[FAILED]", object.BucketName, object.Name, object.VersionId, err)
							fmt.Println("[FAILED]", object.BucketName, object.Name, object.VersionId, err)
							continue
						}
						helper.Logger.Println(5, "[DELETED]", object.BucketName, object.Name, object.VersionId)
						fmt.Println("[DELETED]", object.BucketName, object.Name, object.VersionId)
					}
				}
				if truncated == true {
					request.KeyMarker = nextMarker
					request.VersionIdMarker = nextVerIdMarker
				} else {
					break
				}

			}
		}

	}
	return nil
}
// If a rule has an empty prifex ,the days in it will be consider as a default days for all objects that not specified in
// other rules. For this reason, we have two conditions to check if a object has expired and should be deleted
//  if defaultConfig == true
//                    for each object           check if object name has a prifix
//  list all objects --------------->loop rules---------------------------------->
//                                                                      |     NO
//                                                                      |--------> days = default days ---
//                                                                      |     YES                         |->delete object if expired
//                                                                      |--------> days = specify days ---
//
//  if defaultConfig == false
//                 for each rule get objects by prefix
//  iterator rules ----------------------------------> loop objects-------->delete object if expired
If a rule has an empty prifex ,the days in it will be consider as a default days for all objects that not specified in
other rules. For this reason, we have two conditions to check if a object has expired and should be deleted
if defaultConfig == true
for each object           check if object name has a prifix
list all objects >loop rules>
|     NO
|> days = default days
|     YES                         |->delete object if expired
|> days = specify days

if defaultConfig == false
for each rule get objects by prefix
iterator rules > loop objects>delete object if expired
// If a rule has an empty prifex the days in it will be consider as a default days for all objects that not specified in // other rules . For this reason we have two conditions to check if a object has expired and should be deleted // if defaultConfig == true // for each object check if object name has a prifix // list all objects --------------- > loop rules ---------------------------------- > // | NO // | -------- > days = default days --- // | YES | - > delete object if expired // | -------- > days = specify days --- // // if defaultConfig == false // for each rule get objects by prefix // iterator rules ---------------------------------- > loop objects -------- > delete object if expired
func retrieveBucket(lc types.LifeCycle) error {
	defaultConfig := false
	defaultDays := 0
	bucket, err := yig.MetaStorage.GetBucket(lc.BucketName, false)
	if err != nil {
		return err
	}
	rules := bucket.LC.Rule
	for _, rule := range rules {
		if rule.Prefix == "" {
			defaultConfig = true
			defaultDays, err = strconv.Atoi(rule.Expiration)
			if err != nil {
				return err
			}
		}
	}
	var request datatype.ListObjectsRequest
	request.Versioned = false
	request.MaxKeys = 1000
	if defaultConfig == true {
		for {
			retObjects, _, truncated, nextMarker, nextVerIdMarker, err := yig.ListObjectsInternal(bucket.Name, request)
			if err != nil {
				return err
			}
			for _, object := range retObjects {
				prefixMatch := false
				matchDays := 0
				for _, rule := range rules {
					if rule.Prefix == "" {
						continue
					}
					if strings.HasPrefix(object.Name, rule.Prefix) == false {
						continue
					}
					prefixMatch = true
					matchDays, err = strconv.Atoi(rule.Expiration)
					if err != nil {
						return err
					}
				}
				days := 0
				if prefixMatch == true {
					days = matchDays
				} else {
					days = defaultDays
				}
				helper.Debugln("inteval:", time.Since(object.LastModifiedTime).Seconds())
				if checkIfExpiration(object.LastModifiedTime, days) {
					helper.Debugln("come here")
					if object.NullVersion {
						object.VersionId = ""
					}
					_, err = yig.DeleteObject(object.BucketName, object.Name, object.VersionId, common.Credential{})
					if err != nil {
						helper.Logger.Println(5, "[FAILED]", object.BucketName, object.Name, object.VersionId, err)
						fmt.Println("[FAILED]", object.BucketName, object.Name, object.VersionId, err)
						continue
					}
					helper.Logger.Println(5, "[DELETED]", object.BucketName, object.Name, object.VersionId)
					fmt.Println("[DELETED]", object.BucketName, object.Name, object.VersionId)
				}
			}
			if truncated == true {
				request.KeyMarker = nextMarker
				request.VersionIdMarker = nextVerIdMarker
			} else {
				break
			}
		}
	} else {
		for _, rule := range rules {
			if rule.Prefix == "" {
				continue
			}
			days, _ := strconv.Atoi(rule.Expiration)
			if err != nil {
				return err
			}
			request.Prefix = rule.Prefix
			for {
				retObjects, _, truncated, nextMarker, nextVerIdMarker, err := yig.ListObjectsInternal(bucket.Name, request)
				if err != nil {
					return err
				}
				for _, object := range retObjects {
					if checkIfExpiration(object.LastModifiedTime, days) {
						_, err = yig.DeleteObject(object.BucketName, object.Name, object.VersionId, common.Credential{})
						if err != nil {
							logger.Println(5, "failed to delete object:", object.Name, object.BucketName)
							helper.Logger.Println(5, "[FAILED]", object.BucketName, object.Name, object.VersionId, err)
							fmt.Println("[FAILED]", object.BucketName, object.Name, object.VersionId, err)
							continue
						}
						helper.Logger.Println(5, "[DELETED]", object.BucketName, object.Name, object.VersionId)
						fmt.Println("[DELETED]", object.BucketName, object.Name, object.VersionId)
					}
				}
				if truncated == true {
					request.KeyMarker = nextMarker
					request.VersionIdMarker = nextVerIdMarker
				} else {
					break
				}
			}
		}
	}
	return nil
}
func retrieveBucket ( lc types . LifeCycle ) error { defaultConfig := false defaultDays := 0 bucket , err := yig . MetaStorage . GetBucket ( lc . BucketName , false ) if err != nil { return err } rules := bucket . LC . Rule for _ , rule := range rules { if rule . Prefix == " " { defaultConfig = true defaultDays , err = strconv . Atoi ( rule . Expiration ) if err != nil { return err } } } var request datatype . ListObjectsRequest request . Versioned = false request . MaxKeys = 1000 if defaultConfig == true { for { retObjects , _ , truncated , nextMarker , nextVerIdMarker , err := yig . ListObjectsInternal ( bucket . Name , request ) if err != nil { return err } for _ , object := range retObjects { prefixMatch := false matchDays := 0 for _ , rule := range rules { if rule . Prefix == " " { continue } if strings . HasPrefix ( object . Name , rule . Prefix ) == false { continue } prefixMatch = true matchDays , err = strconv . Atoi ( rule . Expiration ) if err != nil { return err } } days := 0 if prefixMatch == true { days = matchDays } else { days = defaultDays } helper . Debugln ( " " , time . Since ( object . LastModifiedTime ) . Seconds ( ) ) if checkIfExpiration ( object . LastModifiedTime , days ) { helper . Debugln ( " " ) if object . NullVersion { object . VersionId = " " } _ , err = yig . DeleteObject ( object . BucketName , object . Name , object . VersionId , common . Credential { } ) if err != nil { helper . Logger . Println ( 5 , " " , object . BucketName , object . Name , object . VersionId , err ) fmt . Println ( " " , object . BucketName , object . Name , object . VersionId , err ) continue } helper . Logger . Println ( 5 , " " , object . BucketName , object . Name , object . VersionId ) fmt . Println ( " " , object . BucketName , object . Name , object . VersionId ) } } if truncated == true { request . KeyMarker = nextMarker request . VersionIdMarker = nextVerIdMarker } else { break } } } else { for _ , rule := range rules { if rule . Prefix == " " { continue } days , _ := strconv . Atoi ( rule . Expiration ) if err != nil { return err } request . Prefix = rule . Prefix for { retObjects , _ , truncated , nextMarker , nextVerIdMarker , err := yig . ListObjectsInternal ( bucket . Name , request ) if err != nil { return err } for _ , object := range retObjects { if checkIfExpiration ( object . LastModifiedTime , days ) { _ , err = yig . DeleteObject ( object . BucketName , object . Name , object . VersionId , common . Credential { } ) if err != nil { logger . Println ( 5 , " " , object . Name , object . BucketName ) helper . Logger . Println ( 5 , " " , object . BucketName , object . Name , object . VersionId , err ) fmt . Println ( " " , object . BucketName , object . Name , object . VersionId , err ) continue } helper . Logger . Println ( 5 , " " , object . BucketName , object . Name , object . VersionId ) fmt . Println ( " " , object . BucketName , object . Name , object . VersionId ) } } if truncated == true { request . KeyMarker = nextMarker request . VersionIdMarker = nextVerIdMarker } else { break } } } } return nil }
If a rule has an empty prifex ,the days in it will be consider as a default days for all objects that not specified in
other rules.
If a rule has an empty prifex the days in it will be consider as a default days for all objects that not specified in other rules .