Merge "Abort migration early when not enough space." into oc-dev am: e6c142174c

am: a4c0a3b2ca

Change-Id: Ie50f0ae2dbf7eb1b868606b75d1ade808d34590b
This commit is contained in:
Jeff Sharkey 2017-04-04 02:05:21 +00:00 committed by android-build-merger
commit 246779028f
2 changed files with 7 additions and 1 deletions

View file

@ -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<std::string> cmd;
cmd.push_back(kCpPath);
cmd.push_back("-p"); /* preserve timestamps, ownership, and permissions */

View file

@ -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;
}