user-mgmt: Update user data file, only for sync.

IPMI user configuration is cross synced with
phosphor-user-manager and written to the non-volatile data
on every boot. This commit limits the write only when
there is real sync issue, and update required.

Tested:
1. Verified the ipmitool user list & commands
2. Verified that file write happens only when there is
real sync update with phosphor-user-manager

Change-Id: Ia40be91f281656288ca96ca44bc9699daee7c3b4
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
diff --git a/user_channel/user_mgmt.cpp b/user_channel/user_mgmt.cpp
index 41ec5fa..a1d2443 100644
--- a/user_channel/user_mgmt.cpp
+++ b/user_channel/user_mgmt.cpp
@@ -1365,7 +1365,7 @@
                           entry("PATH=%s", userMgrObjBasePath));
         return;
     }
-
+    bool updateRequired = false;
     UsersTbl* userData = &usersTbl;
     // user index 0 is reserved, starts with 1
     for (size_t usrIdx = 1; usrIdx <= ipmiMaxUsers; ++usrIdx)
@@ -1392,6 +1392,7 @@
                 if (std::find(usrGrps.begin(), usrGrps.end(), ipmiGrpName) ==
                     usrGrps.end())
                 {
+                    updateRequired = true;
                     // Group "ipmi" is removed so lets remove user in IPMI
                     deleteUserIndex(usrIdx);
                 }
@@ -1407,6 +1408,7 @@
                             .userPrivAccess[getUsrMgmtSyncIndex()]
                             .privilege != priv)
                     {
+                        updateRequired = true;
                         for (size_t chIndex = 0; chIndex < ipmiMaxChannels;
                              ++chIndex)
                         {
@@ -1417,6 +1419,7 @@
                     }
                     if (userData->user[usrIdx].userEnabled != usrEnabled)
                     {
+                        updateRequired = true;
                         userData->user[usrIdx].userEnabled = usrEnabled;
                     }
                 }
@@ -1426,6 +1429,7 @@
             }
             else
             {
+                updateRequired = true;
                 deleteUserIndex(usrIdx);
             }
         }
@@ -1449,6 +1453,7 @@
         if (std::find(usrGrps.begin(), usrGrps.end(), ipmiGrpName) !=
             usrGrps.end())
         {
+            updateRequired = true;
             // CREATE NEW USER
             if (true != addUserEntry(userName, usrPriv, usrEnabled))
             {
@@ -1457,8 +1462,11 @@
         }
     }
 
-    // All userData slots update done. Lets write the data
-    writeUserData();
+    if (updateRequired)
+    {
+        // All userData slots update done. Lets write the data
+        writeUserData();
+    }
 
     return;
 }