Merge "trying to fix md5 Change-Id: I4ec037f76aa965bc818afe924942adbe9a080b36" into twrp2.4

This commit is contained in:
Dees Troy
2013-03-18 09:57:29 -05:00
committed by Gerrit Code Review
4 changed files with 23 additions and 12 deletions
+19 -3
View File
@@ -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;
+1 -5
View File
@@ -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)
{
+2 -3
View File
@@ -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<string> tokens;
while (ss >> buf)
tokens.push_back(buf);
+1 -1
View File
@@ -30,6 +30,6 @@ class twrpDigest {
private:
int read_md5digest(void);
string md5fn;
vector<string> lines;
string line;
unsigned char md5sum[MD5LENGTH];
};