@@ -948,7 +948,7 @@ FabricTable::AddOrUpdateInner(FabricIndex fabricIndex, bool isAddition, Crypto::
948
948
return CHIP_NO_ERROR;
949
949
}
950
950
951
- CHIP_ERROR FabricTable::Delete (FabricIndex fabricIndex)
951
+ CHIP_ERROR FabricTable::Delete (FabricIndex fabricIndex, bool cleanup )
952
952
{
953
953
MATTER_TRACE_SCOPE (" Delete" , " Fabric" );
954
954
VerifyOrReturnError (mStorage != nullptr , CHIP_ERROR_INVALID_ARGUMENT);
@@ -1002,39 +1002,46 @@ CHIP_ERROR FabricTable::Delete(FabricIndex fabricIndex)
1002
1002
}
1003
1003
}
1004
1004
1005
- if (! fabricIsInitialized)
1005
+ if (fabricIsInitialized)
1006
1006
{
1007
- // Make sure to return the error our API promises, not whatever storage
1008
- // chose to return.
1009
- return CHIP_ERROR_NOT_FOUND;
1010
- }
1011
-
1012
- // Since fabricIsInitialized was true, fabric is not null.
1013
- fabricInfo->Reset ();
1014
-
1015
- if (!mNextAvailableFabricIndex .HasValue ())
1016
- {
1017
- // We must have been in a situation where CHIP_CONFIG_MAX_FABRICS is 254
1018
- // and our fabric table was full, so there was no valid next index. We
1019
- // have a single available index now, though; use it as
1020
- // mNextAvailableFabricIndex.
1021
- mNextAvailableFabricIndex .SetValue (fabricIndex);
1022
- }
1023
- // If StoreFabricIndexInfo fails here, that's probably OK. When we try to
1024
- // read things from storage later we will realize there is nothing for this
1025
- // index.
1026
- StoreFabricIndexInfo ();
1007
+ // Since fabricIsInitialized was true, fabric is not null.
1008
+ fabricInfo->Reset ();
1027
1009
1028
- // If we ever start moving the FabricInfo entries around in the array on
1029
- // delete, we should update DeleteAllFabrics to handle that.
1030
- if (mFabricCount == 0 )
1031
- {
1032
- ChipLogError (FabricProvisioning, " Trying to delete a fabric, but the current fabric count is already 0" );
1010
+ if (!mNextAvailableFabricIndex .HasValue ())
1011
+ {
1012
+ // We must have been in a situation where CHIP_CONFIG_MAX_FABRICS is 254
1013
+ // and our fabric table was full, so there was no valid next index. We
1014
+ // have a single available index now, though; use it as
1015
+ // mNextAvailableFabricIndex.
1016
+ mNextAvailableFabricIndex .SetValue (fabricIndex);
1017
+ }
1018
+ // If StoreFabricIndexInfo fails here, that's probably OK. When we try to
1019
+ // read things from storage later we will realize there is nothing for this
1020
+ // index.
1021
+ StoreFabricIndexInfo ();
1022
+
1023
+ // If we ever start moving the FabricInfo entries around in the array on
1024
+ // delete, we should update DeleteAllFabrics to handle that.
1025
+ if (mFabricCount == 0 )
1026
+ {
1027
+ ChipLogError (FabricProvisioning, " Trying to delete a fabric, but the current fabric count is already 0" );
1028
+ }
1029
+ else
1030
+ {
1031
+ mFabricCount --;
1032
+ ChipLogProgress (FabricProvisioning, " Fabric (0x%x) deleted." , static_cast <unsigned >(fabricIndex));
1033
+ }
1033
1034
}
1034
1035
else
1035
1036
{
1036
- mFabricCount --;
1037
- ChipLogProgress (FabricProvisioning, " Fabric (0x%x) deleted." , static_cast <unsigned >(fabricIndex));
1037
+ // Don't return here if we're doing a cleanup, as we want to remove all data,
1038
+ // even if incomplete.
1039
+ if (!cleanup)
1040
+ {
1041
+ // Make sure to return the error our API promises, not whatever storage
1042
+ // chose to return.
1043
+ return CHIP_ERROR_NOT_FOUND;
1044
+ }
1038
1045
}
1039
1046
1040
1047
if (mDelegateListRoot != nullptr )
@@ -1050,10 +1057,14 @@ CHIP_ERROR FabricTable::Delete(FabricIndex fabricIndex)
1050
1057
}
1051
1058
}
1052
1059
1053
- // Only return error after trying really hard to remove everything we could
1054
- ReturnErrorOnFailure (metadataErr);
1055
- ReturnErrorOnFailure (opKeyErr);
1056
- ReturnErrorOnFailure (opCertsErr);
1060
+ // Don't return error if we're doing a cleanup, some data may be missing.
1061
+ if (!cleanup)
1062
+ {
1063
+ // Only return error after trying really hard to remove everything we could
1064
+ ReturnErrorOnFailure (metadataErr);
1065
+ ReturnErrorOnFailure (opKeyErr);
1066
+ ReturnErrorOnFailure (opCertsErr);
1067
+ }
1057
1068
1058
1069
return CHIP_NO_ERROR;
1059
1070
}
0 commit comments