summaryrefslogtreecommitdiffstats
path: root/twrpDU.cpp
diff options
context:
space:
mode:
authorVojtech Bocek <vbocek@gmail.com>2014-03-11 22:08:23 +0100
committerVojtech Bocek <vbocek@gmail.com>2014-03-13 14:55:12 +0100
commit05f87d6ccaa2d4666dd97cb1d2eeb88bd4e5306f (patch)
treecc437d7f9e3166215dbbd973486ec6a43a590bab /twrpDU.cpp
parentCheck to ensure that selinux_handle is populated before using (diff)
downloadandroid_bootable_recovery-05f87d6ccaa2d4666dd97cb1d2eeb88bd4e5306f.tar
android_bootable_recovery-05f87d6ccaa2d4666dd97cb1d2eeb88bd4e5306f.tar.gz
android_bootable_recovery-05f87d6ccaa2d4666dd97cb1d2eeb88bd4e5306f.tar.bz2
android_bootable_recovery-05f87d6ccaa2d4666dd97cb1d2eeb88bd4e5306f.tar.lz
android_bootable_recovery-05f87d6ccaa2d4666dd97cb1d2eeb88bd4e5306f.tar.xz
android_bootable_recovery-05f87d6ccaa2d4666dd97cb1d2eeb88bd4e5306f.tar.zst
android_bootable_recovery-05f87d6ccaa2d4666dd97cb1d2eeb88bd4e5306f.zip
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);
}