From 3fdcda46629e8e7fc19e89c51350b1e6f151e05e Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Wed, 30 Nov 2016 12:29:37 -0600 Subject: Improve backup & wipe exclusion handling Rename twrpDU.* to exclude.* Remove global variable for du and replace with partition specific variables. Use separate exclusion lists for backups and wiping. Clean up some includes Fix some parenthesis in twrp.cpp that I messed up. Note: twrpTarMain command line utility compiles but probably does not work correctly yet due to not properly setting part_settings Change-Id: Idec9c3e6a8782ba53f3420fa79ba33394f4f85fb --- Android.mk | 2 +- data.cpp | 1 + exclude.cpp | 108 +++++++++++++++++++++++++++++++++++++++++ exclude.hpp | 43 +++++++++++++++++ gui/object.cpp | 2 +- gui/pages.cpp | 1 + gui/resources.cpp | 1 + partition.cpp | 22 ++++++--- partitionmanager.cpp | 9 ++-- partitions.hpp | 4 +- twrp.cpp | 12 ++--- twrpDU.cpp | 115 -------------------------------------------- twrpDU.hpp | 54 --------------------- twrpTar.cpp | 21 ++++++-- twrpTar.hpp | 3 +- twrpTarMain/Android.mk | 8 +-- twrpTarMain/twrpTarMain.cpp | 13 ++--- 17 files changed, 212 insertions(+), 207 deletions(-) create mode 100644 exclude.cpp create mode 100644 exclude.hpp delete mode 100644 twrpDU.cpp delete mode 100644 twrpDU.hpp diff --git a/Android.mk b/Android.mk index a73311e69..553777554 100644 --- a/Android.mk +++ b/Android.mk @@ -44,7 +44,7 @@ LOCAL_SRC_FILES := \ twrp.cpp \ fixContexts.cpp \ twrpTar.cpp \ - twrpDU.cpp \ + exclude.cpp \ twrpDigest.cpp \ digest/md5.c \ find_file.cpp \ diff --git a/data.cpp b/data.cpp index 775570169..b034bf802 100644 --- a/data.cpp +++ b/data.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/exclude.cpp b/exclude.cpp new file mode 100644 index 000000000..f992ecf02 --- /dev/null +++ b/exclude.cpp @@ -0,0 +1,108 @@ +/* + Copyright 2013 to 2016 TeamWin + This file is part of TWRP/TeamWin Recovery Project. + + TWRP is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + TWRP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with TWRP. If not, see . +*/ + +extern "C" { + #include "libtar/libtar.h" +} +#include +#include +#include +#include +#include +#include +#include "exclude.hpp" +#include "twrp-functions.hpp" +#include "gui/gui.hpp" +#include "twcommon.h" + +using namespace std; + +extern bool datamedia; + +TWExclude::TWExclude() { + add_relative_dir("."); + add_relative_dir(".."); + add_relative_dir("lost+found"); +} + +void TWExclude::add_relative_dir(const string& dir) { + relativedir.push_back(dir); +} + +void TWExclude::clear_relative_dir(string dir) { + vector::iterator iter = relativedir.begin(); + while (iter != relativedir.end()) { + if (*iter == dir) + iter = relativedir.erase(iter); + else + iter++; + } +} + +void TWExclude::add_absolute_dir(const string& dir) { + absolutedir.push_back(TWFunc::Remove_Trailing_Slashes(dir)); +} + +uint64_t TWExclude::Get_Folder_Size(const string& Path) { + DIR* d; + struct dirent* de; + struct stat st; + uint64_t dusize = 0; + string FullPath; + + d = opendir(Path.c_str()); + if (d == NULL) { + gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Path)(strerror(errno))); + return 0; + } + + while ((de = readdir(d)) != NULL) { + FullPath = Path + "/"; + FullPath += de->d_name; + if (lstat(FullPath.c_str(), &st)) { + gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(FullPath)(strerror(errno))); + LOGINFO("Real error: Unable to stat '%s'\n", FullPath.c_str()); + continue; + } + if ((st.st_mode & S_IFDIR) && !check_skip_dirs(FullPath) && de->d_type != DT_SOCK) { + dusize += Get_Folder_Size(FullPath); + } else if (st.st_mode & S_IFREG) { + dusize += (uint64_t)(st.st_size); + } + } + closedir(d); + return dusize; +} + +bool TWExclude::check_relative_skip_dirs(const string& dir) { + return std::find(relativedir.begin(), relativedir.end(), dir) != relativedir.end(); +} + +bool TWExclude::check_absolute_skip_dirs(const string& path) { + return std::find(absolutedir.begin(), absolutedir.end(), path) != absolutedir.end(); +} + +bool TWExclude::check_skip_dirs(const string& path) { + string normalized = TWFunc::Remove_Trailing_Slashes(path); + size_t slashIdx = normalized.find_last_of('/'); + if(slashIdx != std::string::npos && slashIdx+1 < normalized.size()) { + if(check_relative_skip_dirs(normalized.substr(slashIdx+1))) + return true; + } + return check_absolute_skip_dirs(normalized); +} diff --git a/exclude.hpp b/exclude.hpp new file mode 100644 index 000000000..5cdc41609 --- /dev/null +++ b/exclude.hpp @@ -0,0 +1,43 @@ +/* + Copyright 2013 to 2016 TeamWin + This file is part of TWRP/TeamWin Recovery Project. + + TWRP is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + TWRP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with TWRP. If not, see . +*/ + +#ifndef TWEXCLUDE_HPP +#define TWEXCLUDE_HPP + +#include +#include + +using namespace std; + +class TWExclude { + +public: + TWExclude(); + uint64_t Get_Folder_Size(const string& Path); // Gets the folder's size using stat + void add_absolute_dir(const string& Path); + void add_relative_dir(const string& Path); + bool check_relative_skip_dirs(const string& dir); + bool check_absolute_skip_dirs(const string& path); + bool check_skip_dirs(const string& path); + void clear_relative_dir(string dir); +private: + vector absolutedir; + vector relativedir; +}; + +#endif diff --git a/gui/object.cpp b/gui/object.cpp index 14df14fc1..e7d1bf99b 100644 --- a/gui/object.cpp +++ b/gui/object.cpp @@ -2,7 +2,7 @@ #include #include - +#include #include extern "C" { diff --git a/gui/pages.cpp b/gui/pages.cpp index 115d6b35d..b6b72966a 100644 --- a/gui/pages.cpp +++ b/gui/pages.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "../twrp-functions.hpp" #include "../partitions.hpp" diff --git a/gui/resources.cpp b/gui/resources.cpp index 9c97dad18..8884dd796 100644 --- a/gui/resources.cpp +++ b/gui/resources.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "../minzip/Zip.h" extern "C" { diff --git a/partition.cpp b/partition.cpp index 3f2374a47..78b11ecab 100644 --- a/partition.cpp +++ b/partition.cpp @@ -43,7 +43,7 @@ #include "twrp-functions.hpp" #include "twrpDigest.hpp" #include "twrpTar.hpp" -#include "twrpDU.hpp" +#include "exclude.hpp" #include "infomanager.hpp" #include "set_metadata.h" #include "gui/gui.hpp" @@ -866,9 +866,13 @@ void TWPartition::Setup_Data_Media() { } DataManager::SetValue("tw_has_internal", 1); DataManager::SetValue("tw_has_data_media", 1); - du.add_absolute_dir(Mount_Point + "/misc/vold"); - du.add_absolute_dir(Mount_Point + "/.layout_version"); - du.add_absolute_dir(Mount_Point + "/system/storage.xml"); + backup_exclusions.add_absolute_dir("/data/data/com.google.android.music/files"); + backup_exclusions.add_absolute_dir(Mount_Point + "/misc/vold"); + wipe_exclusions.add_absolute_dir(Mount_Point + "/misc/vold"); + backup_exclusions.add_absolute_dir(Mount_Point + "/.layout_version"); + wipe_exclusions.add_absolute_dir(Mount_Point + "/.layout_version"); + backup_exclusions.add_absolute_dir(Mount_Point + "/system/storage.xml"); + wipe_exclusions.add_absolute_dir(Mount_Point + "/system/storage.xml"); } else { if (Mount(true) && TWFunc::Path_Exists(Mount_Point + "/media/0")) { Storage_Path = Mount_Point + "/media/0"; @@ -876,7 +880,8 @@ void TWPartition::Setup_Data_Media() { UnMount(true); } } - du.add_absolute_dir(Mount_Point + "/media"); + backup_exclusions.add_absolute_dir(Mount_Point + "/media"); + wipe_exclusions.add_absolute_dir(Mount_Point + "/media"); } void TWPartition::Find_Real_Block_Device(string& Block, bool Display_Error) { @@ -2113,7 +2118,7 @@ bool TWPartition::Wipe_Data_Without_Wiping_Media_Func(const string& parent __unu dir = parent; dir.append(de->d_name); - if (du.check_skip_dirs(dir)) { + if (wipe_exclusions.check_skip_dirs(dir)) { LOGINFO("skipped '%s'\n", dir.c_str()); continue; } @@ -2168,6 +2173,7 @@ bool TWPartition::Backup_Tar(PartitionSettings *part_settings, pid_t *tar_fork_p Full_FileName = part_settings->Backup_Folder + "/" + Backup_FileName; tar.has_data_media = Has_Data_Media; tar.part_settings = part_settings; + tar.backup_exclusions = &backup_exclusions; tar.setdir(Backup_Path); tar.setfn(Full_FileName); tar.setsize(Backup_Size); @@ -2490,7 +2496,7 @@ bool TWPartition::Update_Size(bool Display_Error) { if (Has_Data_Media) { if (Mount(Display_Error)) { unsigned long long data_media_used, actual_data; - Used = du.Get_Folder_Size(Mount_Point); + Used = backup_exclusions.Get_Folder_Size(Mount_Point); Backup_Size = Used; int bak = (int)(Used / 1048576LLU); int fre = (int)(Free / 1048576LLU); @@ -2502,7 +2508,7 @@ bool TWPartition::Update_Size(bool Display_Error) { } } else if (Has_Android_Secure) { if (Mount(Display_Error)) - Backup_Size = du.Get_Folder_Size(Backup_Path); + Backup_Size = backup_exclusions.Get_Folder_Size(Backup_Path); else { if (!Was_Already_Mounted) UnMount(false); diff --git a/partitionmanager.cpp b/partitionmanager.cpp index b04cc9ab8..079d476b3 100644 --- a/partitionmanager.cpp +++ b/partitionmanager.cpp @@ -40,7 +40,7 @@ #include "twrp-functions.hpp" #include "fixContexts.hpp" #include "twrpDigest.hpp" -#include "twrpDU.hpp" +#include "exclude.hpp" #include "set_metadata.h" #include "tw_atomic.hpp" #include "gui/gui.hpp" @@ -835,9 +835,10 @@ int TWPartitionManager::Run_Backup(bool adbbackup) { int total_time = (int) difftime(total_stop, total_start); uint64_t actual_backup_size; - if (!adbbackup) - actual_backup_size = du.Get_Folder_Size(part_settings.Backup_Folder); - else + if (!adbbackup) { + TWExclude twe; + actual_backup_size = twe.Get_Folder_Size(part_settings.Backup_Folder); + } else actual_backup_size = part_settings.file_bytes + part_settings.img_bytes; actual_backup_size /= (1024LLU * 1024LLU); diff --git a/partitions.hpp b/partitions.hpp index 4b9354fd8..3f2e40a5d 100644 --- a/partitions.hpp +++ b/partitions.hpp @@ -21,7 +21,7 @@ #include #include -#include "twrpDU.hpp" +#include "exclude.hpp" #include "tw_atomic.hpp" #include "progresstracking.hpp" @@ -215,6 +215,8 @@ private: bool Can_Flash_Img; // Indicates if this partition can have images flashed to it via the GUI bool Mount_Read_Only; // Only mount this partition as read-only bool Is_Adopted_Storage; // Indicates that this partition is for adopted storage (android_expand) + TWExclude backup_exclusions; + TWExclude wipe_exclusions; friend class TWPartitionManager; friend class DataManager; diff --git a/twrp.cpp b/twrp.cpp index 816265989..3cd716f71 100644 --- a/twrp.cpp +++ b/twrp.cpp @@ -45,7 +45,6 @@ extern "C" { #include "partitions.hpp" #include "openrecoveryscript.hpp" #include "variables.h" -#include "twrpDU.hpp" #ifdef TW_USE_NEW_MINADBD #include "adb.h" #else @@ -64,7 +63,6 @@ extern int adb_server_main(int is_daemon, int server_port, int /* reply_fd */); TWPartitionManager PartitionManager; int Log_Offset; bool datamedia; -twrpDU du; static void Print_Prop(const char *key, const char *name, void *cookie) { printf("%s=%s\n", key, name); @@ -235,19 +233,19 @@ int main(int argc, char **argv) { } else if (*argptr == 'p') { Shutdown = true; } else if (*argptr == 's') { - if (strncmp(argptr, "send_intent", strlen("send_intent") == 0)) { + if (strncmp(argptr, "send_intent", strlen("send_intent")) == 0) { ptr = argptr + strlen("send_intent") + 1; Send_Intent = *ptr; - } else if (strncmp(argptr, "security", strlen("security") == 0)) { + } else if (strncmp(argptr, "security", strlen("security")) == 0) { LOGINFO("Security update\n"); - } else if (strncmp(argptr, "sideload", strlen("sideload") == 0)) { + } else if (strncmp(argptr, "sideload", strlen("sideload")) == 0) { if (!OpenRecoveryScript::Insert_ORS_Command("sideload\n")) break; - } else if (strncmp(argptr, "stages", strlen("stages") == 0)) { + } else if (strncmp(argptr, "stages", strlen("stages")) == 0) { LOGINFO("ignoring stages command\n"); } } else if (*argptr == 'r') { - if (strncmp(argptr, "reason", strlen("reason") == 0)) { + if (strncmp(argptr, "reason", strlen("reason")) == 0) { ptr = argptr + strlen("reason") + 1; gui_print("%s\n", ptr); } diff --git a/twrpDU.cpp b/twrpDU.cpp deleted file mode 100644 index 08dfdcbea..000000000 --- a/twrpDU.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - Copyright 2013 TeamWin - This file is part of TWRP/TeamWin Recovery Project. - - TWRP is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - TWRP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with TWRP. If not, see . -*/ - -extern "C" { - #include "libtar/libtar.h" -} -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "twrpDU.hpp" -#include "twrp-functions.hpp" -#include "gui/gui.hpp" - -using namespace std; - -extern bool datamedia; - -twrpDU::twrpDU() { - add_relative_dir("."); - add_relative_dir(".."); - add_relative_dir("lost+found"); - add_absolute_dir("/data/data/com.google.android.music/files"); -} - -void twrpDU::add_relative_dir(const string& dir) { - relativedir.push_back(dir); -} - -void twrpDU::clear_relative_dir(string dir) { - vector::iterator iter = relativedir.begin(); - while (iter != relativedir.end()) { - if (*iter == dir) - iter = relativedir.erase(iter); - else - iter++; - } -} - -void twrpDU::add_absolute_dir(const string& dir) { - absolutedir.push_back(TWFunc::Remove_Trailing_Slashes(dir)); -} - -vector twrpDU::get_absolute_dirs(void) { - return absolutedir; -} - -uint64_t twrpDU::Get_Folder_Size(const string& Path) { - DIR* d; - struct dirent* de; - struct stat st; - uint64_t dusize = 0; - string FullPath; - - d = opendir(Path.c_str()); - if (d == NULL) { - gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Path)(strerror(errno))); - return 0; - } - - while ((de = readdir(d)) != NULL) { - FullPath = Path + "/"; - FullPath += de->d_name; - if (lstat(FullPath.c_str(), &st)) { - gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(FullPath)(strerror(errno))); - LOGINFO("Real error: Unable to stat '%s'\n", FullPath.c_str()); - continue; - } - if ((st.st_mode & S_IFDIR) && !check_skip_dirs(FullPath) && de->d_type != DT_SOCK) { - dusize += Get_Folder_Size(FullPath); - } else if (st.st_mode & S_IFREG) { - dusize += (uint64_t)(st.st_size); - } - } - closedir(d); - return dusize; -} - -bool twrpDU::check_relative_skip_dirs(const string& dir) { - return std::find(relativedir.begin(), relativedir.end(), dir) != relativedir.end(); -} - -bool twrpDU::check_absolute_skip_dirs(const string& path) { - return std::find(absolutedir.begin(), absolutedir.end(), path) != absolutedir.end(); -} - -bool twrpDU::check_skip_dirs(const string& path) { - string normalized = TWFunc::Remove_Trailing_Slashes(path); - size_t slashIdx = normalized.find_last_of('/'); - if(slashIdx != std::string::npos && slashIdx+1 < normalized.size()) { - if(check_relative_skip_dirs(normalized.substr(slashIdx+1))) - return true; - } - return check_absolute_skip_dirs(normalized); -} diff --git a/twrpDU.hpp b/twrpDU.hpp deleted file mode 100644 index e947de9c2..000000000 --- a/twrpDU.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright 2013 TeamWin - This file is part of TWRP/TeamWin Recovery Project. - - TWRP is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - TWRP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with TWRP. If not, see . -*/ - -#ifndef TWRPDU_HPP -#define TWRPDU_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "twcommon.h" - -using namespace std; - -class twrpDU { - -public: - twrpDU(); - uint64_t Get_Folder_Size(const string& Path); // Gets the folder's size using stat - void add_absolute_dir(const string& Path); - void add_relative_dir(const string& Path); - bool check_relative_skip_dirs(const string& dir); - bool check_absolute_skip_dirs(const string& path); - bool check_skip_dirs(const string& path); - vector get_absolute_dirs(void); - void clear_relative_dir(string dir); -private: - vector absolutedir; - vector relativedir; -}; - -extern twrpDU du; -#endif diff --git a/twrpTar.cpp b/twrpTar.cpp index 06e3b629a..3c07a97d1 100644 --- a/twrpTar.cpp +++ b/twrpTar.cpp @@ -71,6 +71,7 @@ twrpTar::twrpTar(void) { tar_type.readfunc = read; input_fd = -1; output_fd = -1; + backup_exclusions = NULL; } twrpTar::~twrpTar(void) { @@ -108,12 +109,18 @@ int twrpTar::createTarFork(pid_t *tar_fork_pid) { char cmd[512]; file_count = 0; + if (backup_exclusions == NULL) { + LOGINFO("backup_exclusions is NULL\n"); + return -1; + } +#ifndef BUILD_TWRPTAR_MAIN if (part_settings->adbbackup) { std::string Backup_FileName(tarfn); if (!twadbbu::Write_TWFN(Backup_FileName, Total_Backup_Size, use_compression)) return -1; } +#endif if (pipe(progress_pipe) < 0) { LOGINFO("Error creating progress tracking pipe\n"); @@ -168,7 +175,7 @@ int twrpTar::createTarFork(pid_t *tar_fork_pid) { while ((de = readdir(d)) != NULL) { FileName = tardir + "/" + de->d_name; - if (de->d_type == DT_BLK || de->d_type == DT_CHR || du.check_skip_dirs(FileName)) + if (de->d_type == DT_BLK || de->d_type == DT_CHR || backup_exclusions->check_skip_dirs(FileName)) continue; if (de->d_type == DT_DIR) { item_len = strlen(de->d_name); @@ -183,9 +190,9 @@ int twrpTar::createTarFork(pid_t *tar_fork_pid) { _exit(-1); } file_count = (unsigned long long)(ret); - regular_size += du.Get_Folder_Size(FileName); + regular_size += backup_exclusions->Get_Folder_Size(FileName); } else { - encrypt_size += du.Get_Folder_Size(FileName); + encrypt_size += backup_exclusions->Get_Folder_Size(FileName); } } else if (de->d_type == DT_REG) { stat(FileName.c_str(), &st); @@ -216,7 +223,7 @@ int twrpTar::createTarFork(pid_t *tar_fork_pid) { while ((de = readdir(d)) != NULL) { FileName = tardir + "/" + de->d_name; - if (de->d_type == DT_BLK || de->d_type == DT_CHR || du.check_skip_dirs(FileName)) + if (de->d_type == DT_BLK || de->d_type == DT_CHR || backup_exclusions->check_skip_dirs(FileName)) continue; if (de->d_type == DT_DIR) { item_len = strlen(de->d_name); @@ -657,7 +664,7 @@ int twrpTar::Generate_TarList(string Path, std::vector *TarList, while ((de = readdir(d)) != NULL) { FileName = Path + "/" + de->d_name; - if (de->d_type == DT_BLK || de->d_type == DT_CHR || du.check_skip_dirs(FileName)) + if (de->d_type == DT_BLK || de->d_type == DT_CHR || backup_exclusions->check_skip_dirs(FileName)) continue; TarItem.fn = FileName; TarItem.thread_id = *thread_id; @@ -698,10 +705,12 @@ int twrpTar::extractTar() { gui_err("restore_error=Error during restore process."); return -1; } +#ifndef BUILD_TWRPTAR_MAIN if (part_settings->adbbackup) { if (!twadbbu::Write_TWEOF()) return -1; } +#endif return 0; } @@ -1404,8 +1413,10 @@ int twrpTar::closeTar() { #endif } else { +#ifndef BUILD_TWRPTAR_MAIN if (!twadbbu::Write_TWEOF()) return -1; +#endif } if (input_fd >= 0) close(input_fd); diff --git a/twrpTar.hpp b/twrpTar.hpp index 49d373c13..78c4c5978 100644 --- a/twrpTar.hpp +++ b/twrpTar.hpp @@ -27,7 +27,7 @@ extern "C" { #include #include #include -#include "twrpDU.hpp" +#include "exclude.hpp" #include "progresstracking.hpp" #include "partitions.hpp" #include "twrp-functions.hpp" @@ -69,6 +69,7 @@ public: string partition_name; string backup_folder; PartitionSettings *part_settings; + TWExclude *backup_exclusions; private: int extract(); diff --git a/twrpTarMain/Android.mk b/twrpTarMain/Android.mk index 71b9bcd00..f948708d9 100644 --- a/twrpTarMain/Android.mk +++ b/twrpTarMain/Android.mk @@ -8,14 +8,14 @@ LOCAL_SRC_FILES:= \ ../twrp-functions.cpp \ ../twrpTar.cpp \ ../tarWrite.c \ - ../twrpDU.cpp \ + ../exclude.cpp \ ../progresstracking.cpp \ ../gui/twmsg.cpp LOCAL_CFLAGS:= -g -c -W -DBUILD_TWRPTAR_MAIN LOCAL_C_INCLUDES += bionic -LOCAL_STATIC_LIBRARIES := libc libtar_static +LOCAL_STATIC_LIBRARIES := libc libtar_static libz ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0) LOCAL_C_INCLUDES += external/stlport/stlport bionic/libstdc++/include LOCAL_STATIC_LIBRARIES += libstlport_static @@ -52,13 +52,13 @@ LOCAL_SRC_FILES:= \ ../twrp-functions.cpp \ ../twrpTar.cpp \ ../tarWrite.c \ - ../twrpDU.cpp \ + ../exclude.cpp \ ../progresstracking.cpp \ ../gui/twmsg.cpp LOCAL_CFLAGS:= -g -c -W -DBUILD_TWRPTAR_MAIN LOCAL_C_INCLUDES += bionic -LOCAL_SHARED_LIBRARIES := libc libtar +LOCAL_SHARED_LIBRARIES := libc libtar libz ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0) LOCAL_C_INCLUDES += external/stlport/stlport bionic/libstdc++/include LOCAL_SHARED_LIBRARIES += libstlport_static diff --git a/twrpTarMain/twrpTarMain.cpp b/twrpTarMain/twrpTarMain.cpp index ff35f47ce..df40426e4 100644 --- a/twrpTarMain/twrpTarMain.cpp +++ b/twrpTarMain/twrpTarMain.cpp @@ -19,14 +19,12 @@ #include "../twrp-functions.hpp" #include "../twrpTar.hpp" -#include "../twrpDU.hpp" +#include "../exclude.hpp" #include "../progresstracking.hpp" #include "../gui/gui.hpp" #include "../gui/twmsg.h" #include -twrpDU du; - void gui_msg(const char* text) { if (text) { @@ -166,11 +164,14 @@ int main(int argc, char **argv) { } } + TWExclude exclude; + exclude.add_absolute_dir("/data/media"); tar.has_data_media = has_data_media; tar.setdir(Directory); tar.setfn(Tar_Filename); - tar.setsize(du.Get_Folder_Size(Directory)); + tar.setsize(exclude.Get_Folder_Size(Directory)); tar.use_compression = use_compression; + tar.backup_exclusions = &exclude; #ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS if (userdata_encryption && !use_encryption) { printf("userdata encryption set without encryption option\n"); @@ -186,14 +187,14 @@ int main(int argc, char **argv) { } #endif if (action == 1) { - if (tar.createTarFork(&progress, tar_fork_pid) != 0) { + if (tar.createTarFork(&tar_fork_pid) != 0) { sync(); return -1; } sync(); printf("\n\ntar created successfully.\n"); } else if (action == 2) { - if (tar.extractTarFork(&progress) != 0) { + if (tar.extractTarFork() != 0) { sync(); return -1; } -- cgit v1.2.3