@ -404,8 +404,7 @@ func (sys *IAMSys) DeletePolicy(policyName string) error {
defer sys . store . unlock ( )
defer sys . store . unlock ( )
err := sys . store . deletePolicyDoc ( policyName )
err := sys . store . deletePolicyDoc ( policyName )
switch err . ( type ) {
if err == errNoSuchPolicy {
case ObjectNotFound :
// Ignore error if policy is already deleted.
// Ignore error if policy is already deleted.
err = nil
err = nil
}
}
@ -417,7 +416,6 @@ func (sys *IAMSys) DeletePolicy(policyName string) error {
var usersType [ ] IAMUserType
var usersType [ ] IAMUserType
for u , mp := range sys . iamUserPolicyMap {
for u , mp := range sys . iamUserPolicyMap {
if mp . Policy == policyName {
if mp . Policy == policyName {
usersToDel = append ( usersToDel , u )
cr , ok := sys . iamUsersMap [ u ]
cr , ok := sys . iamUsersMap [ u ]
if ! ok {
if ! ok {
// This case cannot happen
// This case cannot happen
@ -429,6 +427,7 @@ func (sys *IAMSys) DeletePolicy(policyName string) error {
} else {
} else {
usersType = append ( usersType , regularUser )
usersType = append ( usersType , regularUser )
}
}
usersToDel = append ( usersToDel , u )
}
}
}
}
for i , u := range usersToDel {
for i , u := range usersToDel {
@ -538,8 +537,7 @@ func (sys *IAMSys) DeleteUser(accessKey string) error {
// It is ok to ignore deletion error on the mapped policy
// It is ok to ignore deletion error on the mapped policy
sys . store . deleteMappedPolicy ( accessKey , regularUser , false )
sys . store . deleteMappedPolicy ( accessKey , regularUser , false )
err := sys . store . deleteUserIdentity ( accessKey , regularUser )
err := sys . store . deleteUserIdentity ( accessKey , regularUser )
switch err . ( type ) {
if err == errNoSuchUser {
case ObjectNotFound :
// ignore if user is already deleted.
// ignore if user is already deleted.
err = nil
err = nil
}
}
@ -1020,14 +1018,11 @@ func (sys *IAMSys) RemoveUsersFromGroup(group string, members []string) error {
// len(gi.Members) == 0 here.
// len(gi.Members) == 0 here.
// Remove the group from storage. First delete the
// Remove the group from storage. First delete the
// mapped policy.
// mapped policy. No-mapped-policy case is ignored.
err := sys . store . deleteMappedPolicy ( group , regularUser , true )
if err := sys . store . deleteMappedPolicy ( group , regularUser , true ) ; err != nil && err != errNoSuchPolicy {
// No-mapped-policy case is ignored.
if err != nil && err != errNoSuchPolicy {
return err
return err
}
}
err = sys . store . deleteGroupInfo ( group )
if err := sys . store . deleteGroupInfo ( group ) ; err != nil && err != errNoSuchGroup {
if err != nil {
return err
return err
}
}
@ -1195,7 +1190,7 @@ func (sys *IAMSys) policyDBSet(name, policy string, userType IAMUserType, isGrou
// Handle policy mapping removal
// Handle policy mapping removal
if policy == "" {
if policy == "" {
if err := sys . store . deleteMappedPolicy ( name , userType , isGroup ) ; err != nil {
if err := sys . store . deleteMappedPolicy ( name , userType , isGroup ) ; err != nil && err != errNoSuchPolicy {
return err
return err
}
}
if ! isGroup {
if ! isGroup {