diff --git a/src/rootfstreemanager.cc b/src/rootfstreemanager.cc index 50e91908..dfe99451 100644 --- a/src/rootfstreemanager.cc +++ b/src/rootfstreemanager.cc @@ -29,6 +29,23 @@ RootfsTreeManager::RootfsTreeManager(const PackageConfig& pconfig, const Bootloa keys_{keys}, cfg_{pconfig} {} +std::tuple 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); @@ -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..."; diff --git a/src/rootfstreemanager.h b/src/rootfstreemanager.h index 2fae5410..39296fbe 100644 --- a/src/rootfstreemanager.h +++ b/src/rootfstreemanager.h @@ -57,6 +57,7 @@ class RootfsTreeManager : public OstreeManager, public Downloader { uint64_t uncompressedSize; }; + std::tuple prePullCheck(const DeltaStat& delta_stat) const; std::string getCurrentHash() const override { return sysroot_->getDeploymentHash(OSTree::Sysroot::Deployment::kCurrent); }