reset: Replace service files with filesystem APIs

In the factory reset function, the read-write and preserved
partitions are cleared via systemd service files. The call
to run these services is asynchronous.
Replace these services files with C++ filesystem APIs so
that it is known when the file deletion starts and completes
to be able to notify the host when a reset operation is
taking place.

Part of openbmc/openbmc#3210

Tested: Verified factory reset still clears the read-write
and preserved partitions.

Change-Id: I7575a2e97a544b1e8692148e8664bdd14fdfb90f
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index a3b1c9c..baeecdc 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -295,37 +295,26 @@
         }
     }
 
+    // Clear the read-write partitions.
     for (const auto& it : activations)
     {
-        auto serviceFile =
-            "obmc-flash-bios-ubiclear@pnor-rw-" + it.first + ".service";
-
-        // Clear the read-write partitions.
-        auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
-                                          SYSTEMD_INTERFACE, "StartUnit");
-        method.append(serviceFile, "replace");
-        auto reply = bus.call(method);
-
-        if (reply.is_method_error())
+        auto rwDir = PNOR_RW_PREFIX + it.first;
+        if (fs::is_directory(rwDir))
         {
-            log<level::ERR>("Failed to clear read-write partitions",
-                            entry("SERVICE_FILE=%s", serviceFile.c_str()));
-            elog<InternalFailure>();
+            for (const auto& iter : fs::directory_iterator(rwDir))
+            {
+                fs::remove_all(iter);
+            }
         }
     }
-    static constexpr auto serviceFile =
-        "obmc-flash-bios-ubiclear@pnor-prsv.service";
-    // Clear the preserved partition.
-    auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
-                                      SYSTEMD_INTERFACE, "StartUnit");
-    method.append(serviceFile, "replace");
-    auto reply = bus.call(method);
 
-    if (reply.is_method_error())
+    // Clear the preserved partition.
+    if (fs::is_directory(PNOR_PRSV))
     {
-        log<level::ERR>("Failed to clear preserved partition",
-                        entry("SERVICE_FILE=%s", serviceFile));
-        elog<InternalFailure>();
+        for (const auto& iter : fs::directory_iterator(PNOR_PRSV))
+        {
+            fs::remove_all(iter);
+        }
     }
 
     return;