summaryrefslogtreecommitdiffstats
path: root/twrpDU.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'twrpDU.cpp')
-rw-r--r--twrpDU.cpp51
1 files changed, 27 insertions, 24 deletions
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 <fstream>
#include <string>
#include <vector>
+#include <algorithm>
#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<string> 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);
}