From cdcfee48b9720d589a4e2cd43725e8229ca336f9 Mon Sep 17 00:00:00 2001 From: bigbiff bigbiff Date: Wed, 27 Feb 2013 21:11:26 -0500 Subject: use md5.c for computation of md5sums create a framework for computing digests and reading digests in TWRP add space for backwards compatibility with bb md5sum Change-Id: Ia18e3f430eed5eba22e5052d39b9b8d88ecd4536 --- partitionmanager.cpp | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'partitionmanager.cpp') diff --git a/partitionmanager.cpp b/partitionmanager.cpp index 895d3617f..9beb2575f 100644 --- a/partitionmanager.cpp +++ b/partitionmanager.cpp @@ -40,6 +40,7 @@ #include "data.hpp" #include "twrp-functions.hpp" #include "fixPermissions.hpp" +#include "twrpDigest.hpp" #ifdef TW_INCLUDE_CRYPTO #ifdef TW_INCLUDE_JB_CRYPTO @@ -477,6 +478,7 @@ bool TWPartitionManager::Make_MD5(bool generate_md5, string Backup_Folder, strin string command; string Full_File = Backup_Folder + Backup_Filename; string result; + twrpDigest md5sum; if (!generate_md5) return true; @@ -485,30 +487,39 @@ bool TWPartitionManager::Make_MD5(bool generate_md5, string Backup_Folder, strin ui_print(" * Generating md5...\n"); if (TWFunc::Path_Exists(Full_File)) { - command = "cd '" + Backup_Folder + "' && md5sum '" + Backup_Filename + "' > '" + Backup_Filename + ".md5'"; - if (TWFunc::Exec_Cmd(command, result) == 0) { - ui_print(" * MD5 Created.\n"); - return true; - } else { + md5sum.setfn(Backup_Folder + Backup_Filename); + if (md5sum.computeMD5() == 0) + if (md5sum.write_md5digest() == 0) + ui_print(" * MD5 Created.\n"); + else + return -1; + else ui_print(" * MD5 Error!\n"); - return false; - } } else { char filename[512]; int index = 0; + string strfn; sprintf(filename, "%s%03i", Full_File.c_str(), index); + strfn = filename; + ostringstream intToStr; + ostringstream fn; while (TWFunc::Path_Exists(filename) == true) { - ostringstream intToStr; intToStr << index; - ostringstream fn; fn << setw(3) << setfill('0') << intToStr.str(); - command = "cd '" + Backup_Folder + "' && md5sum '" + Backup_Filename + fn.str() + "' > '" + Backup_Filename + fn.str() + ".md5'"; - if (TWFunc::Exec_Cmd(command, result) != 0) { - ui_print(" * MD5 Error.\n"); - return false; + md5sum.setfn(strfn); + if (md5sum.computeMD5() == 0) { + if (md5sum.write_md5digest() != 0) + { + ui_print(" * MD5 Error.\n"); + return false; + } + } + else { + return -1; } index++; sprintf(filename, "%s%03i", Full_File.c_str(), index); + strfn = filename; } if (index == 0) { LOGE("Backup file: '%s' not found!\n", filename); -- cgit v1.2.3