Skip to content

Commit

Permalink
MD5 checking: fix issues introduced with adb backup patchset
Browse files Browse the repository at this point in the history
This patchset will fix issues with creating and checking
md5 checksums with single partitions and subpartitions.

Change-Id: Id2d46af0f0913c944aa1d800c44327cfb47e6bd7
  • Loading branch information
bigbiff authored and jcadduono committed Sep 23, 2016
1 parent c45b2d5 commit 9079c85
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
6 changes: 3 additions & 3 deletions partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ bool TWPartition::Backup(PartitionSettings *part_settings, pid_t *tar_fork_pid)
return false;
}

bool TWPartition::Check_MD5(string restore_folder) {

This comment has been minimized.

Copy link
@sewasewa777

sewasewa777 Jan 29, 2017

string restore_folder

This comment has been minimized.

Copy link
@sewasewa777

sewasewa777 Jan 29, 2017

string restore_folder

This comment has been minimized.

Copy link
@sewasewa777

sewasewa777 Jan 29, 2017

partition.cpp

This comment has been minimized.

Copy link
@sewasewa777
bool TWPartition::Check_MD5(PartitionSettings *part_settings) {
string Full_Filename, md5file;
char split_filename[512];
int index = 0;
Expand All @@ -1621,7 +1621,7 @@ bool TWPartition::Check_MD5(string restore_folder) {
sync();

memset(split_filename, 0, sizeof(split_filename));
Full_Filename = restore_folder + "/" + Backup_FileName;
Full_Filename = part_settings->Restore_Name + "/" + part_settings->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);
Expand All @@ -1647,7 +1647,7 @@ bool TWPartition::Check_MD5(string restore_folder) {
// Single file archive
md5file = Full_Filename + ".md5";
if (!TWFunc::Path_Exists(md5file)) {
gui_msg(Msg(msg::kError, "no_md5_found=No md5 file found for '{1}'. Please unselect Enable MD5 verification to restore.")(split_filename));
gui_msg(Msg(msg::kError, "no_md5_found=No md5 file found for '{1}'. Please unselect Enable MD5 verification to restore.")(md5file));
return false;
}
md5sum.setfn(Full_Filename);
Expand Down
35 changes: 22 additions & 13 deletions partitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,21 @@ bool TWPartitionManager::Backup_Partition(PartitionSettings *part_settings) {
part_settings->Backup_FileName = part_settings->Part->Backup_Name + "." + part_settings->Part->Current_File_System + ".win";
if (part_settings->Part->Backup(part_settings, &tar_fork_pid)) {
bool md5Success = false;
if (part_settings->adbbackup) {
md5Success = true;
}
else
md5Success = Make_MD5(part_settings);

TWFunc::SetPerformanceMode(false);
if (part_settings->Part->Has_SubPartition) {
std::vector<TWPartition*>::iterator subpart;
TWPartition *parentPart = part_settings->Part;

for (subpart = Partitions.begin(); subpart != Partitions.end(); subpart++) {
if ((*subpart)->Can_Be_Backed_Up && (*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == part_settings->Part->Mount_Point) {
part_settings->Part = *subpart;
if ((*subpart)->Can_Be_Backed_Up && (*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == parentPart->Mount_Point) {
part_settings->Backup_FileName = part_settings->Part->Backup_Name + "." + part_settings->Part->Current_File_System + ".win";
if (!(*subpart)->Backup(part_settings, &tar_fork_pid)) {
TWFunc::SetPerformanceMode(false);
Clean_Backup_Folder(part_settings->Backup_Folder);
Expand All @@ -577,20 +587,14 @@ bool TWPartitionManager::Backup_Partition(PartitionSettings *part_settings) {
time(&stop);
int backup_time = (int) difftime(stop, start);
LOGINFO("Partition Backup time: %d\n", backup_time);

if (part_settings->Part->Backup_Method == BM_FILES) {
part_settings->file_time += backup_time;
} else {
part_settings->img_time += backup_time;

}

if (part_settings->adbbackup) {
md5Success = true;
}
else
md5Success = Make_MD5(part_settings);
TWFunc::SetPerformanceMode(false);

return md5Success;
} else {
Clean_Backup_Folder(part_settings->Backup_Folder);
Expand Down Expand Up @@ -889,10 +893,12 @@ bool TWPartitionManager::Restore_Partition(PartitionSettings *part_settings) {
}
if (part_settings->Part->Has_SubPartition) {
std::vector<TWPartition*>::iterator subpart;
TWPartition *parentPart = part_settings->Part;

for (subpart = Partitions.begin(); subpart != Partitions.end(); subpart++) {

if ((*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == part_settings->Part->Mount_Point) {
part_settings->Part = *subpart;
if ((*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == parentPart->Mount_Point) {
part_settings->Part = (*subpart);
if (!(*subpart)->Restore(part_settings)) {
TWFunc::SetPerformanceMode(false);
return false;
Expand Down Expand Up @@ -953,16 +959,19 @@ int TWPartitionManager::Run_Restore(const string& Restore_Name) {
return false;
}

if (check_md5 > 0 && !part_settings.Part->Check_MD5(Restore_Name))
if (check_md5 > 0 && !part_settings.Part->Check_MD5(&part_settings))
return false;
part_settings.partition_count++;
part_settings.total_restore_size += part_settings.Part->Get_Restore_Size(&part_settings);
if (part_settings.Part->Has_SubPartition) {
TWPartition *parentPart = part_settings.Part;
std::vector<TWPartition*>::iterator subpart;

for (subpart = Partitions.begin(); subpart != Partitions.end(); subpart++) {
if ((*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == part_settings.Part->Mount_Point) {
if (check_md5 > 0 && !(*subpart)->Check_MD5(Restore_Name))
part_settings.Backup_FileName = parentPart->Backup_Name + "." + parentPart->Current_File_System + ".win";
part_settings.Part = *subpart;
if ((*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == parentPart->Mount_Point) {
if (check_md5 > 0 && !(*subpart)->Check_MD5(&part_settings))
return false;
part_settings.total_restore_size += (*subpart)->Get_Restore_Size(&part_settings);
}
Expand Down
6 changes: 3 additions & 3 deletions partitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ struct PartitionSettings {
uint64_t img_bytes; // total image bytes of all emmc partitions
uint64_t file_bytes; // total file bytes of all file based partitions
int partition_count; // Number of partitions to restore
ProgressTracking *progress;
enum PartitionManager_Op PM_Method; //Current operation of backup or restore
ProgressTracking *progress; // Keep track of progress in GUI
enum PartitionManager_Op PM_Method; // Current operation of backup or restore
};

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

1 comment on commit 9079c85

@nailyk-fr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR should be submitted through gerrit. Thanks.

Please sign in to comment.