PEL: Repository: Add write() function

Pull the code that writes a PEL object to a file into a separate
function so that it can be called in multiple places.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ic5701fdfb03cca915520222bbbd8bb92a9c47c49
diff --git a/extensions/openpower-pels/repository.cpp b/extensions/openpower-pels/repository.cpp
index 93d2f81..3aeecb6 100644
--- a/extensions/openpower-pels/repository.cpp
+++ b/extensions/openpower-pels/repository.cpp
@@ -96,6 +96,21 @@
 void Repository::add(std::unique_ptr<PEL>& pel)
 {
     auto path = _logPath / getPELFilename(pel->id(), pel->commitTime());
+
+    write(*(pel.get()), path);
+
+    PELAttributes attributes{path, pel->userHeader().actionFlags()};
+
+    using pelID = LogID::Pel;
+    using obmcID = LogID::Obmc;
+    _pelAttributes.emplace(LogID(pelID(pel->id()), obmcID(pel->obmcLogID())),
+                           attributes);
+
+    processAddCallbacks(*pel);
+}
+
+void Repository::write(const PEL& pel, const fs::path& path)
+{
     std::ofstream file{path, std::ios::binary};
 
     if (!file.good())
@@ -109,7 +124,7 @@
         throw file_error::Open();
     }
 
-    auto data = pel->data();
+    auto data = pel.data();
     file.write(reinterpret_cast<const char*>(data.data()), data.size());
 
     if (file.fail())
@@ -123,17 +138,6 @@
                         entry("PATH=%s", path.c_str()));
         throw file_error::Write();
     }
-
-    file.close();
-
-    PELAttributes attributes{path, pel->userHeader().actionFlags()};
-
-    using pelID = LogID::Pel;
-    using obmcID = LogID::Obmc;
-    _pelAttributes.emplace(LogID(pelID(pel->id()), obmcID(pel->obmcLogID())),
-                           attributes);
-
-    processAddCallbacks(*pel);
 }
 
 void Repository::remove(const LogID& id)