From a0220a5bd410d4b342ee1ca84e8381d6bc5f468e Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 3 Apr 2017 17:11:45 -0600 Subject: [PATCH] Abort migration early when not enough space. Otherwise we potentially waste minutes of the users time copying data that will never fit. Also fix bug around storage calculation. It's confusing, but f_bsize is not the value you're looking for; the real block size is f_frsize. Test: builds, boots Bug: 27590986, 36840579 Change-Id: I77c63e259356824cc75a3adcf3f4af567efdc7aa --- MoveTask.cpp | 6 ++++++ Utils.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/MoveTask.cpp b/MoveTask.cpp index 38cca04..ea64a1c 100644 --- a/MoveTask.cpp +++ b/MoveTask.cpp @@ -128,6 +128,12 @@ static status_t execCp(const std::string& fromPath, const std::string& toPath, uint64_t expectedBytes = GetTreeBytes(fromPath); uint64_t startFreeBytes = GetFreeBytes(toPath); + if (expectedBytes > startFreeBytes) { + LOG(ERROR) << "Data size " << expectedBytes << " is too large to fit in free space " + << startFreeBytes; + return -1; + } + std::vector cmd; cmd.push_back(kCpPath); cmd.push_back("-p"); /* preserve timestamps, ownership, and permissions */ diff --git a/Utils.cpp b/Utils.cpp index 72d3801..443df1d 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -432,7 +432,7 @@ status_t NormalizeHex(const std::string& in, std::string& out) { uint64_t GetFreeBytes(const std::string& path) { struct statvfs sb; if (statvfs(path.c_str(), &sb) == 0) { - return (uint64_t)sb.f_bfree * sb.f_bsize; + return (uint64_t) sb.f_bavail * sb.f_frsize; } else { return -1; }