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
This commit is contained in:
parent
fd3dc3c076
commit
a0220a5bd4
2 changed files with 7 additions and 1 deletions
|
@ -128,6 +128,12 @@ static status_t execCp(const std::string& fromPath, const std::string& toPath,
|
||||||
uint64_t expectedBytes = GetTreeBytes(fromPath);
|
uint64_t expectedBytes = GetTreeBytes(fromPath);
|
||||||
uint64_t startFreeBytes = GetFreeBytes(toPath);
|
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;
|
std::vector<std::string> cmd;
|
||||||
cmd.push_back(kCpPath);
|
cmd.push_back(kCpPath);
|
||||||
cmd.push_back("-p"); /* preserve timestamps, ownership, and permissions */
|
cmd.push_back("-p"); /* preserve timestamps, ownership, and permissions */
|
||||||
|
|
|
@ -432,7 +432,7 @@ status_t NormalizeHex(const std::string& in, std::string& out) {
|
||||||
uint64_t GetFreeBytes(const std::string& path) {
|
uint64_t GetFreeBytes(const std::string& path) {
|
||||||
struct statvfs sb;
|
struct statvfs sb;
|
||||||
if (statvfs(path.c_str(), &sb) == 0) {
|
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 {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue