From 15e623db7ac3127aa440ed133a310e6e640f665b Mon Sep 17 00:00:00 2001 From: Gary Peck Date: Wed, 21 Nov 2012 21:07:58 -0800 Subject: check backup image size before restoring Change-Id: I206d34936388c1b072eaaec50e0492710cb80f2e --- partition.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'partition.cpp') diff --git a/partition.cpp b/partition.cpp index 0590d981c..d391f9881 100644 --- a/partition.cpp +++ b/partition.cpp @@ -1300,8 +1300,21 @@ bool TWPartition::Restore_DD(string restore_folder) { string Full_FileName, Command; TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, "Restoring"); - ui_print("Restoring %s...\n", Display_Name.c_str()); Full_FileName = restore_folder + "/" + Backup_FileName; + + if (!Find_Partition_Size()) { + LOGE("Unable to find partition size for '%s'\n", Mount_Point.c_str()); + return false; + } + unsigned long long backup_size = TWFunc::Get_File_Size(Full_FileName); + if (backup_size > Size) { + LOGE("Size (%iMB) of backup '%s' is larger than target device '%s' (%iMB)\n", + (int)(backup_size / 1048576LLU), Full_FileName.c_str(), + Actual_Block_Device.c_str(), (int)(Size / 1048576LLU)); + return false; + } + + ui_print("Restoring %s...\n", Display_Name.c_str()); Command = "dd bs=4096 if='" + Full_FileName + "' of=" + Actual_Block_Device; LOGI("Restore command: '%s'\n", Command.c_str()); system(Command.c_str()); -- cgit v1.2.3