From 65a4c73b1eea5f29f517d8357248c537dc6752ec Mon Sep 17 00:00:00 2001 From: bigbiff bigbiff Date: Fri, 15 Mar 2013 15:17:50 -0400 Subject: trying to fix md5 Change-Id: I4ec037f76aa965bc818afe924942adbe9a080b36 --- partition.cpp | 22 +++++++++++++++++++--- partitionmanager.cpp | 6 +----- twrpDigest.cpp | 5 ++--- twrpDigest.hpp | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/partition.cpp b/partition.cpp index 346c298b2..681604f21 100644 --- a/partition.cpp +++ b/partition.cpp @@ -941,30 +941,46 @@ bool TWPartition::Backup(string backup_folder) { } bool TWPartition::Check_MD5(string restore_folder) { - string Full_Filename; + string Full_Filename, md5file; char split_filename[512]; int index = 0; twrpDigest md5sum; + memset(split_filename, 0, sizeof(split_filename)); Full_Filename = restore_folder + "/" + Backup_FileName; if (!TWFunc::Path_Exists(Full_Filename)) { // This is a split archive, we presume sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index); + LOGI("split_filename: %s\n", split_filename); + md5file = split_filename; + md5file += ".md5"; + if (!TWFunc::Path_Exists(md5file)) { + LOGE("No md5 file found for '%s'.\n", split_filename); + LOGE("Please unselect Enable MD5 verification to restore.\n"); + return false; + } + md5sum.setfn(split_filename); while (index < 1000 && TWFunc::Path_Exists(split_filename)) { - md5sum.setfn(split_filename); if (md5sum.verify_md5digest() != 0) { LOGE("MD5 failed to match on '%s'.\n", split_filename); return false; } index++; sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index); + md5sum.setfn(split_filename); } return true; } else { // Single file archive + md5file = Full_Filename + ".md5"; + if (!TWFunc::Path_Exists(md5file)) { + LOGE("No md5 file found for '%s'.\n", Full_Filename.c_str()); + LOGE("Please unselect Enable MD5 verification to restore.\n"); + return false; + } md5sum.setfn(Full_Filename); if (md5sum.verify_md5digest() != 0) { - LOGE("MD5 failed to match on '%s'.\n", split_filename); + LOGE("MD5 failed to match on '%s'.\n", Full_Filename.c_str()); return false; } else return true; diff --git a/partitionmanager.cpp b/partitionmanager.cpp index 9beb2575f..4364a2252 100644 --- a/partitionmanager.cpp +++ b/partitionmanager.cpp @@ -501,12 +501,8 @@ bool TWPartitionManager::Make_MD5(bool generate_md5, string Backup_Folder, strin string strfn; sprintf(filename, "%s%03i", Full_File.c_str(), index); strfn = filename; - ostringstream intToStr; - ostringstream fn; while (TWFunc::Path_Exists(filename) == true) { - intToStr << index; - fn << setw(3) << setfill('0') << intToStr.str(); - md5sum.setfn(strfn); + md5sum.setfn(filename); if (md5sum.computeMD5() == 0) { if (md5sum.write_md5digest() != 0) { diff --git a/twrpDigest.cpp b/twrpDigest.cpp index 16cda3d68..add498c6c 100644 --- a/twrpDigest.cpp +++ b/twrpDigest.cpp @@ -84,7 +84,7 @@ int twrpDigest::write_md5digest(void) { int twrpDigest::read_md5digest(void) { string md5file = md5fn + ".md5"; - if (TWFunc::read_file(md5file, lines) != 0) + if (TWFunc::read_file(md5file, line) != 0) return -1; return 0; } @@ -94,10 +94,9 @@ int twrpDigest::verify_md5digest(void) { char hex[3]; int i; string md5string; - if (read_md5digest() != 0) return -1; - stringstream ss(lines.at(0)); + stringstream ss(line); vector tokens; while (ss >> buf) tokens.push_back(buf); diff --git a/twrpDigest.hpp b/twrpDigest.hpp index 80828fca5..395c0aea1 100644 --- a/twrpDigest.hpp +++ b/twrpDigest.hpp @@ -30,6 +30,6 @@ class twrpDigest { private: int read_md5digest(void); string md5fn; - vector lines; + string line; unsigned char md5sum[MD5LENGTH]; }; -- cgit v1.2.3