-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "UpdateFilesystemServiceJob.h" | ||
#include <fmt/core.h> | ||
#include <filesystem> | ||
#include <fstream> | ||
#include "BellTar.h" | ||
#include "ServiceTask.h" | ||
|
||
using namespace euph; | ||
|
||
UpdateFilesystemServiceJob::UpdateFilesystemServiceJob(std::string archivePath) | ||
: archivePath(archivePath) {} | ||
|
||
std::string UpdateFilesystemServiceJob::jobTypeName() { | ||
return "UpdateFilesystemServiceJob"; | ||
} | ||
|
||
void UpdateFilesystemServiceJob::run(std::shared_ptr<euph::Context> ctx) { | ||
// First determine the size of the file | ||
std::filesystem::path path(archivePath); | ||
if (!std::filesystem::exists(path)) { | ||
throw ServiceJobFailedException( | ||
fmt::format("Archive at '{}' does not exist.", archivePath)); | ||
} | ||
|
||
size_t fileSize = std::filesystem::file_size(path); | ||
size_t progressReportStep = fileSize / 100; // Report progress every 1% | ||
|
||
// Open the file | ||
std::ifstream fileStream(archivePath, std::ios::in | std::ios::binary); | ||
|
||
if (!fileStream.is_open()) { | ||
throw ServiceJobFailedException( | ||
fmt::format("Failed to open archive at '{}'.", archivePath)); | ||
} | ||
bell::BellTar::reader tarArchive(fileStream); | ||
// Remove directory if it exists | ||
tarArchive.extract_all_files(ctx->rootPath, [&](size_t bytesRead) { | ||
this->reportProgress(ctx, (float)bytesRead / (float)fileSize); | ||
}); | ||
|
||
// We are done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include "ServiceTask.h" | ||
|
||
namespace euph { | ||
|
||
/** | ||
* @brief Unpacks a tar archive with a filesystem OTA update. | ||
* | ||
*/ | ||
class UpdateFilesystemServiceJob : euph::ServiceJob { | ||
public: | ||
UpdateFilesystemServiceJob(std::string archivePath); | ||
virtual std::string jobTypeName() override; | ||
virtual void run(std::shared_ptr<euph::Context> ctx) override; | ||
|
||
private: | ||
std::string archivePath; | ||
}; | ||
|
||
} // namespace euph |