From 05f87d6ccaa2d4666dd97cb1d2eeb88bd4e5306f Mon Sep 17 00:00:00 2001 From: Vojtech Bocek Date: Tue, 11 Mar 2014 22:08:23 +0100 Subject: Fix skipping of relative paths and lost+found in twrpDU Change-Id: Ib79029fd6237502338b041a6bc2f9e539536d6ad Signed-off-by: Vojtech Bocek --- twrpDU.cpp | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'twrpDU.cpp') diff --git a/twrpDU.cpp b/twrpDU.cpp index c4446d42a..d2345d768 100644 --- a/twrpDU.cpp +++ b/twrpDU.cpp @@ -27,19 +27,21 @@ extern "C" { #include #include #include +#include #include "twrpDU.hpp" +#include "twrp-functions.hpp" using namespace std; twrpDU::twrpDU() { add_relative_dir("."); add_relative_dir(".."); - add_relative_dir("lost_found"); + add_relative_dir("lost+found"); add_absolute_dir("/data/data/com.google.android.music/files"); parent = ""; } -void twrpDU::add_relative_dir(string dir) { +void twrpDU::add_relative_dir(const string& dir) { relativedir.push_back(dir); } @@ -53,8 +55,8 @@ void twrpDU::clear_relative_dir(string dir) { } } -void twrpDU::add_absolute_dir(string dir) { - absolutedir.push_back(dir); +void twrpDU::add_absolute_dir(const string& dir) { + absolutedir.push_back(TWFunc::Remove_Trailing_Slashes(dir)); } vector twrpDU::get_absolute_dirs(void) { @@ -79,12 +81,7 @@ uint64_t twrpDU::Get_Folder_Size(const string& Path) { while ((de = readdir(d)) != NULL) { - bool skip_dir = false; - if (de->d_type == DT_DIR) { - string dir = de->d_name; - skip_dir = check_skip_dirs(dir); - } - if (de->d_type == DT_DIR && !skip_dir) { + if (de->d_type == DT_DIR && !check_skip_dirs(Path, de->d_name)) { dutemp = Get_Folder_Size((Path + "/" + de->d_name)); dusize += dutemp; dutemp = 0; @@ -98,19 +95,25 @@ uint64_t twrpDU::Get_Folder_Size(const string& Path) { return dusize; } -bool twrpDU::check_skip_dirs(string& dir) { - bool result = false; - for (int i = 0; i < relativedir.size(); ++i) { - if (dir == relativedir.at(i)) { - result = true; - break; - } - } - for (int i = 0; i < absolutedir.size(); ++i) { - if (dir == absolutedir.at(i)) { - result = true; - break; - } +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) { + string normalized = TWFunc::Remove_Trailing_Slashes(path); + return std::find(absolutedir.begin(), absolutedir.end(), normalized) != absolutedir.end(); +} + +bool twrpDU::check_skip_dirs(const string& parent, const string& dir) { + return check_relative_skip_dirs(dir) || check_absolute_skip_dirs(parent + "/" + dir); +} + +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 result; + return check_absolute_skip_dirs(normalized); } -- cgit v1.2.3