blob: b002dbd63726894158947657269feb0829a0779e [file] [log] [blame]
#include "config.h"
#include "usb_manager.hpp"
namespace phosphor
{
namespace usb
{
bool USBManager::run()
{
fs::path dir(usbPath);
if (!fs::exists(dir))
{
return false;
}
for (const auto& p : std::filesystem::directory_iterator(dir))
{
if (p.path().extension() == ".tar")
{
fs::path dstPath{IMG_UPLOAD_DIR / p.path().filename()};
if (fs::exists(dstPath))
{
lg2::info(
"{DSTPATH} already exists in the /tmp/images directory, exit the upgrade",
"DSTPATH", p.path().filename());
break;
}
try
{
return fs::copy_file(fs::absolute(p.path()), dstPath);
}
catch (const std::exception& e)
{
lg2::error("Error when copying {SRC} to /tmp/images: {ERROR}",
"SRC", p.path(), "ERROR", e.what());
}
break;
}
}
return false;
}
} // namespace usb
} // namespace phosphor