update_engine: Use utils::FileSize when finding the size of a file.
The utils::FileSize funciton can find the size of a block device correctly.
Use it instead of the adhoc methods used around the codebase.
BUG=chromium:415867
TEST=Ran a butterfly-paladin tryjob with --hwtest.
Change-Id: Id6fd37f04b136b4265bde9b1f56c379a5d9c30f9
Reviewed-on: https://chromium-review.googlesource.com/217418
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
diff --git a/p2p_manager_unittest.cc b/p2p_manager_unittest.cc
index 56ba33b..456c8ad 100644
--- a/p2p_manager_unittest.cc
+++ b/p2p_manager_unittest.cc
@@ -208,19 +208,19 @@
static bool CheckP2PFile(const string& p2p_dir, const string& file_name,
ssize_t expected_size, ssize_t expected_size_xattr) {
string path = p2p_dir + "/" + file_name;
- struct stat statbuf;
char ea_value[64] = { 0 };
ssize_t ea_size;
- if (stat(path.c_str(), &statbuf) != 0) {
+ off_t p2p_size = utils::FileSize(path);
+ if (p2p_size < 0) {
LOG(ERROR) << "File " << path << " does not exist";
return false;
}
if (expected_size != 0) {
- if (statbuf.st_size != expected_size) {
+ if (p2p_size != expected_size) {
LOG(ERROR) << "Expected size " << expected_size
- << " but size was " << statbuf.st_size;
+ << " but size was " << p2p_size;
return false;
}
}