Skip to content

Commit d3ec059

Browse files
Dees-Troyjcadduono
authored andcommitted
Fix image flashing
PS2: full_filename is not a dir PS3: use a consistent format of always assuming directory is missing the trailing / + fix whitespace alignment Change-Id: Ib963473ae10571b3d069b326d024ca04c7224dda
1 parent c0d40de commit d3ec059

File tree

4 files changed

+46
-47
lines changed

4 files changed

+46
-47
lines changed

gui/action.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,18 +1737,11 @@ int GUIAction::flashimage(std::string arg __unused)
17371737
{
17381738
int op_status = 0;
17391739

1740-
PartitionSettings part_settings;
17411740
operation_start("Flash Image");
17421741
string path, filename;
17431742
DataManager::GetValue("tw_zip_location", path);
17441743
DataManager::GetValue("tw_file", filename);
1745-
part_settings.Backup_Folder = path + "/" + filename;
1746-
unsigned long long total_bytes = TWFunc::Get_File_Size(part_settings.Backup_Folder);
1747-
ProgressTracking progress(total_bytes);
1748-
part_settings.progress = &progress;
1749-
part_settings.adbbackup = false;
1750-
part_settings.PM_Method = PM_RESTORE;
1751-
if (PartitionManager.Flash_Image(&part_settings))
1744+
if (PartitionManager.Flash_Image(path, filename))
17521745
op_status = 0; // success
17531746
else
17541747
op_status = 1; // fail

partition.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ bool TWPartition::Check_MD5(PartitionSettings *part_settings) {
16621662

16631663
bool TWPartition::Restore(PartitionSettings *part_settings) {
16641664
TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, gui_parse_text("{@restoring_hdr}"));
1665-
LOGINFO("Restore filename is: %s%s\n", part_settings->Backup_Folder.c_str(), Backup_FileName.c_str());
1665+
LOGINFO("Restore filename is: %s/%s\n", part_settings->Backup_Folder.c_str(), Backup_FileName.c_str());
16661666

16671667
string Restore_File_System = Get_Restore_File_System(part_settings);
16681668

@@ -2167,7 +2167,7 @@ bool TWPartition::Backup_Tar(PartitionSettings *part_settings, pid_t *tar_fork_p
21672167
#endif
21682168

21692169
Backup_FileName = Backup_Name + "." + Current_File_System + ".win";
2170-
Full_FileName = part_settings->Backup_Folder + Backup_FileName;
2170+
Full_FileName = part_settings->Backup_Folder + "/" + Backup_FileName;
21712171
tar.has_data_media = Has_Data_Media;
21722172
tar.part_settings = part_settings;
21732173
tar.setdir(Backup_Path);
@@ -2227,7 +2227,7 @@ bool TWPartition::Raw_Read_Write(PartitionSettings *part_settings) {
22272227
if (part_settings->adbbackup)
22282228
destfn = TW_ADB_BACKUP;
22292229
else
2230-
destfn = part_settings->Backup_Folder + Backup_FileName;
2230+
destfn = part_settings->Backup_Folder + "/" + Backup_FileName;
22312231
}
22322232
else {
22332233
destfn = Actual_Block_Device;
@@ -2448,7 +2448,7 @@ bool TWPartition::Restore_Image(PartitionSettings *part_settings) {
24482448
if (part_settings->adbbackup)
24492449
Full_FileName = TW_ADB_RESTORE;
24502450
else
2451-
Full_FileName = part_settings->Backup_Folder + Backup_FileName;
2451+
Full_FileName = part_settings->Backup_Folder + "/" + Backup_FileName;
24522452

24532453
if (Restore_File_System == "emmc") {
24542454
if (!part_settings->adbbackup)
@@ -2607,10 +2607,7 @@ uint64_t TWPartition::Get_Max_FileSize() {
26072607
bool TWPartition::Flash_Image(PartitionSettings *part_settings) {
26082608
string Restore_File_System, full_filename;
26092609

2610-
if (part_settings->Part != NULL)
2611-
full_filename = part_settings->Backup_Folder + "/" + Backup_FileName;
2612-
else
2613-
full_filename = part_settings->Backup_Folder; // Flash image action from GUI
2610+
full_filename = part_settings->Backup_Folder + "/" + Backup_FileName;
26142611

26152612
LOGINFO("Image filename is: %s\n", Backup_FileName.c_str());
26162613

partitionmanager.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ bool TWPartitionManager::Make_MD5(PartitionSettings *part_settings)
486486

487487
if (part_settings->Part == NULL)
488488
return false;
489-
string Full_File = part_settings->Backup_Folder + part_settings->Part->Backup_FileName;
489+
string Full_File = part_settings->Backup_Folder + "/" + part_settings->Part->Backup_FileName;
490490
twrpDigest md5sum;
491491

492492
if (!part_settings->generate_md5)
@@ -622,7 +622,7 @@ void TWPartitionManager::Clean_Backup_Folder(string Backup_Folder) {
622622
if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, ".."))
623623
continue;
624624

625-
string path = Backup_Folder + p->d_name;
625+
string path = Backup_Folder + "/" + p->d_name;
626626

627627
size_t dot = path.find_last_of(".") + 1;
628628
if (path.substr(dot) == "win" || path.substr(dot) == "md5" || path.substr(dot) == "info") {
@@ -647,7 +647,7 @@ int TWPartitionManager::Cancel_Backup() {
647647
if (tar_fork_pid != 0) {
648648
DataManager::GetValue(TW_BACKUP_NAME, Backup_Name);
649649
DataManager::GetValue(TW_BACKUPS_FOLDER_VAR, Backup_Folder);
650-
Full_Backup_Path = Backup_Folder + "/" + Backup_Name + "/";
650+
Full_Backup_Path = Backup_Folder + "/" + Backup_Name;
651651
LOGINFO("Killing pid: %d\n", tar_fork_pid);
652652
kill(tar_fork_pid, SIGUSR2);
653653
while (kill(tar_fork_pid, 0) == 0) {
@@ -714,9 +714,9 @@ int TWPartitionManager::Run_Backup(bool adbbackup) {
714714
}
715715

716716
LOGINFO("Backup Name is: '%s'\n", Backup_Name.c_str());
717-
part_settings.Backup_Folder = part_settings.Backup_Folder + "/" + Backup_Name + "/";
717+
part_settings.Backup_Folder = part_settings.Backup_Folder + "/" + Backup_Name;
718718

719-
LOGINFO("Full_Backup_Path is: '%s'\n", part_settings.Backup_Folder.c_str());
719+
LOGINFO("Backup_Folder is: '%s'\n", part_settings.Backup_Folder.c_str());
720720

721721
LOGINFO("Calculating backup details...\n");
722722
DataManager::GetValue("tw_backup_list", Backup_List);
@@ -864,7 +864,7 @@ int TWPartitionManager::Run_Backup(bool adbbackup) {
864864
Update_System_Details();
865865
UnMount_Main_Partitions();
866866
gui_msg(Msg(msg::kHighlight, "backup_completed=[BACKUP COMPLETED IN {1} SECONDS]")(total_time)); // the end
867-
string backup_log = part_settings.Backup_Folder + "recovery.log";
867+
string backup_log = part_settings.Backup_Folder + "/recovery.log";
868868
TWFunc::copy_file("/tmp/recovery.log", backup_log, 0644);
869869
tw_set_default_metadata(backup_log.c_str());
870870

@@ -2248,13 +2248,13 @@ bool TWPartitionManager::Remove_MTP_Storage(unsigned int Storage_ID) {
22482248
return false;
22492249
}
22502250

2251-
bool TWPartitionManager::Flash_Image(PartitionSettings *part_settings) {
2251+
bool TWPartitionManager::Flash_Image(string& path, string& filename) {
22522252
int check, partition_count = 0;
22532253
TWPartition* flash_part = NULL;
22542254
string Flash_List, flash_path, full_filename;
22552255
size_t start_pos = 0, end_pos = 0;
22562256

2257-
full_filename = part_settings->Backup_Folder;
2257+
full_filename = path + "/" + filename;
22582258

22592259
gui_msg("image_flash_start=[IMAGE FLASH STARTED]");
22602260
gui_msg(Msg("img_to_flash=Image to flash: '{1}'")(full_filename));
@@ -2269,6 +2269,14 @@ bool TWPartitionManager::Flash_Image(PartitionSettings *part_settings) {
22692269
}
22702270
}
22712271

2272+
PartitionSettings part_settings;
2273+
part_settings.Backup_Folder = path;
2274+
unsigned long long total_bytes = TWFunc::Get_File_Size(full_filename);
2275+
ProgressTracking progress(total_bytes);
2276+
part_settings.progress = &progress;
2277+
part_settings.adbbackup = false;
2278+
part_settings.PM_Method = PM_RESTORE;
2279+
22722280
gui_msg("calc_restore=Calculating restore details...");
22732281
DataManager::GetValue("tw_flash_partition", Flash_List);
22742282
if (!Flash_List.empty()) {
@@ -2298,7 +2306,8 @@ bool TWPartitionManager::Flash_Image(PartitionSettings *part_settings) {
22982306

22992307
DataManager::SetProgress(0.0);
23002308
if (flash_part) {
2301-
if (!flash_part->Flash_Image(part_settings))
2309+
flash_part->Backup_FileName = filename;
2310+
if (!flash_part->Flash_Image(&part_settings))
23022311
return false;
23032312
} else {
23042313
gui_err("invalid_flash=Invalid flash partition specified.");

partitions.hpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,29 @@ struct PartitionList {
3535
unsigned int selected;
3636
};
3737

38-
enum PartitionManager_Op { // PartitionManager Restore Mode for Raw_Read_Write()
38+
enum PartitionManager_Op { // PartitionManager Restore Mode for Raw_Read_Write()
3939
PM_BACKUP = 0,
4040
PM_RESTORE = 1,
4141
};
4242

4343
class TWPartition;
4444

45-
struct PartitionSettings { // Settings for backup session
46-
TWPartition* Part; // Partition to pass to the partition backup loop
47-
std::string Backup_Folder; // Path to restore folder
48-
bool adbbackup; // tell the system we are backing up over adb
49-
bool adb_compression; // 0 == uncompressed, 1 == compressed
50-
bool generate_md5; // tell system to create md5 for partitions
51-
uint64_t total_restore_size; // Total size of restored backup
52-
uint64_t img_bytes_remaining; // remaining img/emmc bytes to backup for progress indicator
53-
uint64_t file_bytes_remaining; // remaining file bytes to backup for progress indicator
54-
uint64_t img_time; // used to calculate how fast we backup images
55-
uint64_t file_time; // used to calculate how fast we backup files
56-
uint64_t img_bytes; // total image bytes of all emmc partitions
57-
uint64_t file_bytes; // total file bytes of all file based partitions
58-
int partition_count; // Number of partitions to restore
59-
ProgressTracking *progress; // Keep track of progress in GUI
60-
enum PartitionManager_Op PM_Method; // Current operation of backup or restore
45+
struct PartitionSettings { // Settings for backup session
46+
TWPartition* Part; // Partition to pass to the partition backup loop
47+
std::string Backup_Folder; // Path to restore folder
48+
bool adbbackup; // tell the system we are backing up over adb
49+
bool adb_compression; // 0 == uncompressed, 1 == compressed
50+
bool generate_md5; // tell system to create md5 for partitions
51+
uint64_t total_restore_size; // Total size of restored backup
52+
uint64_t img_bytes_remaining; // remaining img/emmc bytes to backup for progress indicator
53+
uint64_t file_bytes_remaining; // remaining file bytes to backup for progress indicator
54+
uint64_t img_time; // used to calculate how fast we backup images
55+
uint64_t file_time; // used to calculate how fast we backup files
56+
uint64_t img_bytes; // total image bytes of all emmc partitions
57+
uint64_t file_bytes; // total file bytes of all file based partitions
58+
int partition_count; // Number of partitions to restore
59+
ProgressTracking *progress; // Keep track of progress in GUI
60+
enum PartitionManager_Op PM_Method; // Current operation of backup or restore
6161
};
6262

6363
enum Backup_Method_enum {
@@ -92,7 +92,7 @@ class TWPartition
9292
bool Backup(PartitionSettings *part_settings, pid_t *tar_fork_pid); // Backs up the partition to the folder specified
9393
bool Check_MD5(PartitionSettings *part_settings); // Checks MD5 of a backup
9494
bool Restore(PartitionSettings *part_settings); // Restores the partition using the backup folder provided
95-
unsigned long long Get_Restore_Size(PartitionSettings *part_settings);// Returns the overall restore size of the backup
95+
unsigned long long Get_Restore_Size(PartitionSettings *part_settings); // Returns the overall restore size of the backup
9696
string Backup_Method_By_Name(); // Returns a string of the backup method for human readable output
9797
bool Decrypt(string Password); // Decrypts the partition, return 0 for failure and -1 for success
9898
bool Wipe_Encryption(); // Ignores wipe commands for /data/media devices and formats the original block device
@@ -283,15 +283,15 @@ class TWPartitionManager
283283
void Decrypt_Adopted(); // Attempt to identy and decrypt any adopted storage partitions
284284
void Remove_Partition_By_Path(string Path); // Removes / erases a partition entry from the partition list
285285

286-
bool Flash_Image(PartitionSettings *part_settings); // Flashes an image to a selected partition from the partition list
287-
bool Restore_Partition(struct PartitionSettings *part_settings); // Restore the partitions based on type
286+
bool Flash_Image(string& path, string& filename); // Flashes an image to a selected partition from the partition list
287+
bool Restore_Partition(struct PartitionSettings *part_settings); // Restore the partitions based on type
288288
TWAtomicInt stop_backup;
289289

290290
private:
291291
void Setup_Settings_Storage_Partition(TWPartition* Part); // Sets up settings storage
292292
void Setup_Android_Secure_Location(TWPartition* Part); // Sets up .android_secure if needed
293-
bool Make_MD5(struct PartitionSettings *part_settings); // Generates an MD5 after a backup is made
294-
bool Backup_Partition(struct PartitionSettings *part_settings); // Backup the partitions based on type
293+
bool Make_MD5(struct PartitionSettings *part_settings); // Generates an MD5 after a backup is made
294+
bool Backup_Partition(struct PartitionSettings *part_settings); // Backup the partitions based on type
295295
void Output_Partition(TWPartition* Part); // Outputs partition details to the log
296296
TWPartition* Find_Partition_By_MTP_Storage_ID(unsigned int Storage_ID); // Returns a pointer to a partition based on MTP Storage ID
297297
bool Add_Remove_MTP_Storage(TWPartition* Part, int message_type); // Adds or removes an MTP Storage partition

0 commit comments

Comments
 (0)