Skip to content

Commit 9079c85

Browse files
bigbiffjcadduono
authored andcommitted
MD5 checking: fix issues introduced with adb backup patchset
This patchset will fix issues with creating and checking md5 checksums with single partitions and subpartitions. Change-Id: Id2d46af0f0913c944aa1d800c44327cfb47e6bd7
1 parent c45b2d5 commit 9079c85

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

partition.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ bool TWPartition::Backup(PartitionSettings *part_settings, pid_t *tar_fork_pid)
16121612
return false;
16131613
}
16141614

1615-
bool TWPartition::Check_MD5(string restore_folder) {
1615+
bool TWPartition::Check_MD5(PartitionSettings *part_settings) {
16161616
string Full_Filename, md5file;
16171617
char split_filename[512];
16181618
int index = 0;
@@ -1621,7 +1621,7 @@ bool TWPartition::Check_MD5(string restore_folder) {
16211621
sync();
16221622

16231623
memset(split_filename, 0, sizeof(split_filename));
1624-
Full_Filename = restore_folder + "/" + Backup_FileName;
1624+
Full_Filename = part_settings->Restore_Name + "/" + part_settings->Backup_FileName;
16251625
if (!TWFunc::Path_Exists(Full_Filename)) {
16261626
// This is a split archive, we presume
16271627
sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index);
@@ -1647,7 +1647,7 @@ bool TWPartition::Check_MD5(string restore_folder) {
16471647
// Single file archive
16481648
md5file = Full_Filename + ".md5";
16491649
if (!TWFunc::Path_Exists(md5file)) {
1650-
gui_msg(Msg(msg::kError, "no_md5_found=No md5 file found for '{1}'. Please unselect Enable MD5 verification to restore.")(split_filename));
1650+
gui_msg(Msg(msg::kError, "no_md5_found=No md5 file found for '{1}'. Please unselect Enable MD5 verification to restore.")(md5file));
16511651
return false;
16521652
}
16531653
md5sum.setfn(Full_Filename);

partitionmanager.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,21 @@ bool TWPartitionManager::Backup_Partition(PartitionSettings *part_settings) {
551551
part_settings->Backup_FileName = part_settings->Part->Backup_Name + "." + part_settings->Part->Current_File_System + ".win";
552552
if (part_settings->Part->Backup(part_settings, &tar_fork_pid)) {
553553
bool md5Success = false;
554+
if (part_settings->adbbackup) {
555+
md5Success = true;
556+
}
557+
else
558+
md5Success = Make_MD5(part_settings);
559+
560+
TWFunc::SetPerformanceMode(false);
554561
if (part_settings->Part->Has_SubPartition) {
555562
std::vector<TWPartition*>::iterator subpart;
563+
TWPartition *parentPart = part_settings->Part;
556564

557565
for (subpart = Partitions.begin(); subpart != Partitions.end(); subpart++) {
558-
if ((*subpart)->Can_Be_Backed_Up && (*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == part_settings->Part->Mount_Point) {
566+
part_settings->Part = *subpart;
567+
if ((*subpart)->Can_Be_Backed_Up && (*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == parentPart->Mount_Point) {
568+
part_settings->Backup_FileName = part_settings->Part->Backup_Name + "." + part_settings->Part->Current_File_System + ".win";
559569
if (!(*subpart)->Backup(part_settings, &tar_fork_pid)) {
560570
TWFunc::SetPerformanceMode(false);
561571
Clean_Backup_Folder(part_settings->Backup_Folder);
@@ -577,20 +587,14 @@ bool TWPartitionManager::Backup_Partition(PartitionSettings *part_settings) {
577587
time(&stop);
578588
int backup_time = (int) difftime(stop, start);
579589
LOGINFO("Partition Backup time: %d\n", backup_time);
590+
580591
if (part_settings->Part->Backup_Method == BM_FILES) {
581592
part_settings->file_time += backup_time;
582593
} else {
583594
part_settings->img_time += backup_time;
584595

585596
}
586597

587-
if (part_settings->adbbackup) {
588-
md5Success = true;
589-
}
590-
else
591-
md5Success = Make_MD5(part_settings);
592-
TWFunc::SetPerformanceMode(false);
593-
594598
return md5Success;
595599
} else {
596600
Clean_Backup_Folder(part_settings->Backup_Folder);
@@ -889,10 +893,12 @@ bool TWPartitionManager::Restore_Partition(PartitionSettings *part_settings) {
889893
}
890894
if (part_settings->Part->Has_SubPartition) {
891895
std::vector<TWPartition*>::iterator subpart;
896+
TWPartition *parentPart = part_settings->Part;
892897

893898
for (subpart = Partitions.begin(); subpart != Partitions.end(); subpart++) {
894-
895-
if ((*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == part_settings->Part->Mount_Point) {
899+
part_settings->Part = *subpart;
900+
if ((*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == parentPart->Mount_Point) {
901+
part_settings->Part = (*subpart);
896902
if (!(*subpart)->Restore(part_settings)) {
897903
TWFunc::SetPerformanceMode(false);
898904
return false;
@@ -953,16 +959,19 @@ int TWPartitionManager::Run_Restore(const string& Restore_Name) {
953959
return false;
954960
}
955961

956-
if (check_md5 > 0 && !part_settings.Part->Check_MD5(Restore_Name))
962+
if (check_md5 > 0 && !part_settings.Part->Check_MD5(&part_settings))
957963
return false;
958964
part_settings.partition_count++;
959965
part_settings.total_restore_size += part_settings.Part->Get_Restore_Size(&part_settings);
960966
if (part_settings.Part->Has_SubPartition) {
967+
TWPartition *parentPart = part_settings.Part;
961968
std::vector<TWPartition*>::iterator subpart;
962969

963970
for (subpart = Partitions.begin(); subpart != Partitions.end(); subpart++) {
964-
if ((*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == part_settings.Part->Mount_Point) {
965-
if (check_md5 > 0 && !(*subpart)->Check_MD5(Restore_Name))
971+
part_settings.Backup_FileName = parentPart->Backup_Name + "." + parentPart->Current_File_System + ".win";
972+
part_settings.Part = *subpart;
973+
if ((*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == parentPart->Mount_Point) {
974+
if (check_md5 > 0 && !(*subpart)->Check_MD5(&part_settings))
966975
return false;
967976
part_settings.total_restore_size += (*subpart)->Get_Restore_Size(&part_settings);
968977
}

partitions.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ struct PartitionSettings {
6060
uint64_t img_bytes; // total image bytes of all emmc partitions
6161
uint64_t file_bytes; // total file bytes of all file based partitions
6262
int partition_count; // Number of partitions to restore
63-
ProgressTracking *progress;
64-
enum PartitionManager_Op PM_Method; //Current operation of backup or restore
63+
ProgressTracking *progress; // Keep track of progress in GUI
64+
enum PartitionManager_Op PM_Method; // Current operation of backup or restore
6565
};
6666

6767
enum Backup_Method_enum {
@@ -94,7 +94,7 @@ class TWPartition
9494
bool Can_Resize(); // Checks to see if we have everything needed to be able to resize the current file system
9595
bool Resize(); // Resizes the current file system
9696
bool Backup(PartitionSettings *part_settings, pid_t *tar_fork_pid); // Backs up the partition to the folder specified
97-
bool Check_MD5(string restore_folder); // Checks MD5 of a backup
97+
bool Check_MD5(PartitionSettings *part_settings); // Checks MD5 of a backup
9898
bool Restore(PartitionSettings *part_settings); // Restores the partition using the backup folder provided
9999
unsigned long long Get_Restore_Size(PartitionSettings *part_settings);// Returns the overall restore size of the backup
100100
string Backup_Method_By_Name(); // Returns a string of the backup method for human readable output

0 commit comments

Comments
 (0)