Remove index from list when device is skipped

If there is a duplicate deviceName added in system.json, it will cause
vicious circle that entity-manager crashed with error "file exeists"
and then restart forever.

The index should also be removed when the device is erased from
foundDevices.

Tested:
Add the following config: /usr/share/entity-manager/configurations/x8x8.json
{
    "Exposes": [],
    "Name": "cable_x8x8_$index",
    "Probe": "xyz.openbmc_project.FruDevice({'BOARD_PRODUCT_NAME': '^cable_x8x8$'})",
    "Type": "Board",
    "xyz.openbmc_project.Inventory.I2CLocation": {
        "Bus": "$BUS",
        "Address": "$ADDRESS",
        "Name": "cable_x8x8_$index"
    }
}
root@qbmc:~# busctl tree xyz.openbmc_project.EntityManager | grep cable_x8x8
        | |-/xyz/openbmc_project/inventory/system/board/cable_x8x8_1
        | |-/xyz/openbmc_project/inventory/system/board/cable_x8x8_2
root@qbmc:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/cable_x8x8_1 xyz.openbmc_project.Inventory.I2CLocation
NAME                                      TYPE      SIGNATURE RESULT/VALUE   FLAGS
.Address                                  property  t         82             emits-change
.Bus                                      property  t         6              emits-change
.Name                                     property  s         "cable_x8x8_1" emits-change
root@qbmc:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/cable_x8x8_2 xyz.openbmc_project.Inventory.I2CLocation
NAME                                      TYPE      SIGNATURE RESULT/VALUE   FLAGS
.Address                                  property  t         82             emits-change
.Bus                                      property  t         9              emits-change
.Name                                     property  s         "cable_x8x8_2" emits-change

And then write cable_x8x8 fru data to bus 5, and use "ReScan" method in
FruDevice's dbus.

Before this patch the entity-manager will crash with the following log:

Mar 09 12:41:05 qbmc entity-manager[2713]: Inventory Added: cable_x8x8_1
Mar 09 12:41:06 qbmc entity-manager[2713]: terminate called after throwing an instance of 'sdbusplus::exception::SdBusError'
Mar 09 12:41:06 qbmc entity-manager[2713]:   what():  sd_bus_add_object_vtable: org.freedesktop.DBus.Error.FileExists: File exists

root@qbmc:~# cat /var/configuration/system.json | grep 'xyz.openbmc_project.Inventory.I2CLocation' -A 4
        "xyz.openbmc_project.Inventory.I2CLocation": {
            "Address": 82,
            "Bus": 6,
            "Name": "cable_x8x8_1"
        }
--
        "xyz.openbmc_project.Inventory.I2CLocation": {
            "Address": 82,
            "Bus": 5,
            "Name": "cable_x8x8_1"
        }
--
        "xyz.openbmc_project.Inventory.I2CLocation": {
            "Address": 82,
            "Bus": 9,
            "Name": "cable_x8x8_2"
        }

After adding this patch:
root@qbmc:~# busctl tree xyz.openbmc_project.EntityManager | grep cable_x8x8
        | |-/xyz/openbmc_project/inventory/system/board/cable_x8x8_1
        | |-/xyz/openbmc_project/inventory/system/board/cable_x8x8_2
        | |-/xyz/openbmc_project/inventory/system/board/cable_x8x8_3
root@qbmc:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/cable_x8x8_1 xyz.openbmc_project.Inventory.I2CLocation
NAME                                      TYPE      SIGNATURE RESULT/VALUE   FLAGS
.Address                                  property  t         82             emits-change
.Bus                                      property  t         6              emits-change
.Name                                     property  s         "cable_x8x8_1" emits-change
root@qbmc:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/cable_x8x8_2 xyz.openbmc_project.Inventory.I2CLocation
NAME                                      TYPE      SIGNATURE RESULT/VALUE   FLAGS
.Address                                  property  t         82             emits-change
.Bus                                      property  t         9              emits-change
.Name                                     property  s         "cable_x8x8_2" emits-change
root@qbmc:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/cable_x8x8_3 xyz.openbmc_project.Inventory.I2CLocation
NAME                                      TYPE      SIGNATURE RESULT/VALUE   FLAGS
.Address                                  property  t         82             emits-change
.Bus                                      property  t         5              emits-change
.Name                                     property  s         "cable_x8x8_3" emits-change

Signed-off-by: JinFuLin <JeffLin2@quantatw.com>
Change-Id: I081301a68c12e0c0c8ea4e8f54445dd8ff8b9ed1
diff --git a/src/perform_scan.cpp b/src/perform_scan.cpp
index 44f284c..0ad6509 100644
--- a/src/perform_scan.cpp
+++ b/src/perform_scan.cpp
@@ -495,8 +495,6 @@
 
             pruneRecordExposes(*record);
 
-            recordDiscoveredIdentifiers(usedNames, indexes, probeName, *record);
-
             _systemConfiguration[recordName] = *record;
         }
         _missingConfigurations.erase(recordName);
@@ -504,6 +502,7 @@
         // We've processed the device, remove it and advance the
         // iterator
         itr = foundDevices.erase(itr);
+        recordDiscoveredIdentifiers(usedNames, indexes, probeName, *record);
     }
 
     std::optional<std::string> replaceStr;