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
diff --git a/MoveTask.cpp b/MoveTask.cpp
index 38cca04..ea64a1c 100644
--- a/MoveTask.cpp
+++ b/MoveTask.cpp
@@ -128,6 +128,12 @@
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 */