Skip to content

Commit

Permalink
rootfsmanager: Encapsulate pre-pull free space check func
Browse files Browse the repository at this point in the history
Move the pre-pull free storage space verification to a dedicated method.

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed Sep 1, 2023
1 parent 290770f commit 3b1d331
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/rootfstreemanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ RootfsTreeManager::RootfsTreeManager(const PackageConfig& pconfig, const Bootloa
keys_{keys},
cfg_{pconfig} {}

std::tuple<bool, std::string> RootfsTreeManager::prePullCheck(const DeltaStat& delta_stat) const {
storage::Volume::UsageInfo usage_info;
std::stringstream msg;
bool ok{true};

try {
storage::Volume::getUsageInfo(sysroot_->repoPath(), sysroot_->reservedStorageSpacePercentageDelta(), usage_info);
ok = usage_info.available.first >= delta_stat.uncompressedSize;
msg << "required: " << usage_info.toRelativeType(delta_stat.uncompressedSize) << ", " << usage_info;
} catch (const std::exception& exc) {
LOG_ERROR << "Failed to check if the static delta can fit on a disk, skipping the update size check...; err: "
<< exc.what();
}

return {ok, msg.str()};
}

DownloadResult RootfsTreeManager::Download(const TufTarget& target) {
auto prog_cb = [this](const Uptane::Target& t, const std::string& description, unsigned int progress) {
// report_progress_cb(events_channel.get(), t, description, progress);
Expand Down Expand Up @@ -56,21 +73,15 @@ DownloadResult RootfsTreeManager::Download(const TufTarget& target) {
DeltaStat delta_stat{};
if (getDeltaStatIfAvailable(target, remote, delta_stat)) {
LOG_INFO << "Found and pulled delta stats, checking if update can fit on a disk...";
try {
storage::Volume::UsageInfo usage_info;
storage::Volume::getUsageInfo(sysroot_->repoPath(), sysroot_->reservedStorageSpacePercentageDelta(),
usage_info);
if (usage_info.available.first < delta_stat.uncompressedSize) {
std::stringstream err_msg;
err_msg << "required: " << usage_info.toRelativeType(delta_stat.uncompressedSize) << ", " << usage_info;
return {DownloadResult::Status::DownloadFailed_NoSpace,
"Insufficient storage available; err: " + err_msg.str(), sysroot_->repoPath()};
}
LOG_INFO << "Fetching static delta; required: " << usage_info.toRelativeType(delta_stat.uncompressedSize)
<< usage_info;
} catch (const std::exception& exc) {
LOG_ERROR << "Failed to check if the static delta can fit on a disk, skipping the update size check...; err: "
<< exc.what();
bool ok{false};
std::string msg;
std::tie(ok, msg) = prePullCheck(delta_stat);
if (!ok) {
return {DownloadResult::Status::DownloadFailed_NoSpace, "Insufficient storage available; err: " + msg,
sysroot_->repoPath()};
}
if (!msg.empty()) {
LOG_INFO << "Sufficient storage available; " << msg;
}
} else {
LOG_INFO << "No static delta or static delta stats are found, skipping the update size check...";
Expand Down
1 change: 1 addition & 0 deletions src/rootfstreemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class RootfsTreeManager : public OstreeManager, public Downloader {
uint64_t uncompressedSize;
};

std::tuple<bool, std::string> prePullCheck(const DeltaStat& delta_stat) const;
std::string getCurrentHash() const override {
return sysroot_->getDeploymentHash(OSTree::Sysroot::Deployment::kCurrent);
}
Expand Down

0 comments on commit 3b1d331

Please sign in to comment.