usb: Copy image file to /tmp/images via USB
Traverse the USB mount directory, and copy the first file with
a `.tar` extension under the directory to the `/tmp/images`
directory.
Tested: Manually call the fs::copy_file app locally, test passed.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I8e03b9c3305f5e9d9a1535dd176ecd40dbea8903
diff --git a/usb/usb_manager.hpp b/usb/usb_manager.hpp
new file mode 100644
index 0000000..f3323a8
--- /dev/null
+++ b/usb/usb_manager.hpp
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <phosphor-logging/lg2.hpp>
+
+#include <filesystem>
+
+namespace phosphor
+{
+namespace usb
+{
+namespace fs = std::filesystem;
+
+class USBManager
+{
+ public:
+ ~USBManager() = default;
+ USBManager() = delete;
+ USBManager(const USBManager&) = delete;
+ USBManager(USBManager&&) = default;
+ USBManager& operator=(const USBManager&) = delete;
+ USBManager& operator=(USBManager&&) = default;
+
+ explicit USBManager(const fs::path& path) : usbPath(path)
+ {}
+
+ /** @brief Find the first file with a .tar extension according to the USB
+ * file path.
+ *
+ * @return Success or Fail
+ */
+ bool run();
+
+ private:
+ /** The USB path detected. */
+ const fs::path& usbPath;
+};
+
+} // namespace usb
+} // namespace phosphor