diff --git a/map/framework.cpp b/map/framework.cpp index 7b50b148f2..af44b8d332 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -234,6 +234,12 @@ void Framework::StopLocationFollow() CallDrapeFunction(bind(&df::DrapeEngine::StopLocationFollow, _1)); } +bool Framework::IsEnoughSpaceForMigrate() const +{ + uint64_t const kSpaceSize = 100 /*Mb*/ * 1024 * 1024; + return GetPlatform().GetWritableStorageStatus(kSpaceSize) == Platform::TStorageStatus::STORAGE_OK; +} + void Framework::PreMigrate(ms::LatLon const & position, storage::Storage::TChangeCountryFunction const & change, storage::Storage::TProgressFunction const & progress) diff --git a/map/framework.hpp b/map/framework.hpp index 73bb4c82bb..07fd59958a 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -143,6 +143,7 @@ public: virtual ~Framework(); /// Migrate to new version of very different data. + bool IsEnoughSpaceForMigrate() const; void PreMigrate(ms::LatLon const & position, storage::Storage::TChangeCountryFunction const & change, storage::Storage::TProgressFunction const & progress); void Migrate(); diff --git a/platform/platform.hpp b/platform/platform.hpp index 127c7c019e..186f3d4c9d 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -168,6 +168,7 @@ public: NOT_ENOUGH_SPACE }; TStorageStatus GetWritableStorageStatus(uint64_t neededSize) const; + uint64_t GetWritableStorageSpace() const; /// @name Functions for concurrent tasks. //@{ diff --git a/platform/platform_unix_impl.cpp b/platform/platform_unix_impl.cpp index e7236d2280..fda11526e4 100644 --- a/platform/platform_unix_impl.cpp +++ b/platform/platform_unix_impl.cpp @@ -199,6 +199,18 @@ Platform::TStorageStatus Platform::GetWritableStorageStatus(uint64_t neededSize) return STORAGE_OK; } +uint64_t Platform::GetWritableStorageSpace() const +{ + struct statfs st; + int const ret = statfs(m_writableDir.c_str(), &st); + + LOG(LDEBUG, ("statfs return = ", ret, + "; block size = ", st.f_bsize, + "; blocks available = ", st.f_bavail)); + + return (ret != 0) ? 0 : st.f_bsize * st.f_bavail; +} + namespace pl { void EnumerateFilesByRegExp(string const & directory, string const & regexp,