From 08a4c26a6eb53698fd46680ac2ffdecc4b8d57c6 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 11 May 2017 14:46:24 +0300 Subject: [PATCH] IsEnoughSpaceForDownload() refactoring. --- storage/storage_helpers.cpp | 20 ++++++++++---------- storage/storage_helpers.hpp | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/storage/storage_helpers.cpp b/storage/storage_helpers.cpp index 4ee47f5c52..e319fe3f98 100644 --- a/storage/storage_helpers.cpp +++ b/storage/storage_helpers.cpp @@ -20,25 +20,25 @@ bool IsDownloadFailed(Status status) status == Status::EUnknown; } -bool IsEnoughSpaceForDownload(TMwmSize mwmSize, TMwmSize maxMwmSize) +bool IsEnoughSpaceForDownload(TMwmSize mwmSize) +{ + return GetPlatform().GetWritableStorageStatus(mwmSize) == + Platform::TStorageStatus::STORAGE_OK; +} + +bool IsEnoughSpaceForDownload(TMwmSize mwmSizeDiff, TMwmSize maxMwmSize) { // Mwm size is less than |maxMwmSize|. In case of map update at first we download updated map // and only after that we do delete the obsolete map. So in such a case we might need up to - // kMaxMwmSizeBytes of extra space. - return GetPlatform().GetWritableStorageStatus(mwmSize + maxMwmSize) == - Platform::TStorageStatus::STORAGE_OK; + // |maxMwmSize| of extra space. + return IsEnoughSpaceForDownload(mwmSizeDiff + maxMwmSize); } bool IsEnoughSpaceForDownload(TCountryId const & countryId, Storage const & storage) { NodeAttrs nodeAttrs; storage.GetNodeAttrs(countryId, nodeAttrs); - // The type of nodeAttrs.m_mwmSize and nodeAttrs.m_localMwmSize is TMwmSize (uint64_t). - // The condition below is necessary to prevent passing a big positive number as the first - // parameter of IsEnoughSpaceForDownload(). - return IsEnoughSpaceForDownload(nodeAttrs.m_mwmSize > nodeAttrs.m_localMwmSize - ? nodeAttrs.m_mwmSize - nodeAttrs.m_localMwmSize - : 0, storage.GetMaxMwmSizeBytes()); + return IsEnoughSpaceForDownload(nodeAttrs.m_mwmSize); } bool IsEnoughSpaceForUpdate(TCountryId const & countryId, Storage const & storage) diff --git a/storage/storage_helpers.hpp b/storage/storage_helpers.hpp index edf85bd0ec..dd41f88324 100644 --- a/storage/storage_helpers.hpp +++ b/storage/storage_helpers.hpp @@ -22,11 +22,11 @@ bool IsPointCoveredByDownloadedMaps(m2::PointD const & position, bool IsDownloadFailed(Status status); -bool IsEnoughSpaceForDownload(TMwmSize mwmSize, TMwmSize maxMwmSize); +bool IsEnoughSpaceForDownload(TMwmSize mwmSize); +bool IsEnoughSpaceForDownload(TMwmSize mwmSizeDiff, TMwmSize maxMwmSize); bool IsEnoughSpaceForDownload(TCountryId const & countryId, Storage const & storage); bool IsEnoughSpaceForUpdate(TCountryId const & countryId, Storage const & storage); - /// \brief Calculates limit rect for |countryId| (expandable or not). /// \returns bounding box in mercator coordinates. m2::RectD CalcLimitRect(TCountryId const & countryId,