Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3fdcda46 authored by Ethan Yonker's avatar Ethan Yonker
Browse files

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
parent 0a8a7ceb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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 \
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <time.h>
#include <string>
#include <sstream>
#include <fstream>
#include <cctype>
#include <cutils/properties.h>
#include <unistd.h>
+12 −19
Original line number Diff line number Diff line
/*
		Copyright 2013 TeamWin
		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
@@ -21,33 +21,30 @@ extern "C" {
}
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include "twrpDU.hpp"
#include "exclude.hpp"
#include "twrp-functions.hpp"
#include "gui/gui.hpp"
#include "twcommon.h"

using namespace std;

extern bool datamedia;

twrpDU::twrpDU() {
TWExclude::TWExclude() {
	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) {
void TWExclude::add_relative_dir(const string& dir) {
	relativedir.push_back(dir);
}

void twrpDU::clear_relative_dir(string dir) {
void TWExclude::clear_relative_dir(string dir) {
	vector<string>::iterator iter = relativedir.begin();
	while (iter != relativedir.end()) {
		if (*iter == dir)
@@ -57,15 +54,11 @@ void twrpDU::clear_relative_dir(string dir) {
	}
}

void twrpDU::add_absolute_dir(const string& dir) {
void TWExclude::add_absolute_dir(const string& dir) {
	absolutedir.push_back(TWFunc::Remove_Trailing_Slashes(dir));
}

vector<string> twrpDU::get_absolute_dirs(void) {
	return absolutedir;
}

uint64_t twrpDU::Get_Folder_Size(const string& Path) {
uint64_t TWExclude::Get_Folder_Size(const string& Path) {
	DIR* d;
	struct dirent* de;
	struct stat st;
@@ -96,15 +89,15 @@ uint64_t twrpDU::Get_Folder_Size(const string& Path) {
	return dusize;
}

bool twrpDU::check_relative_skip_dirs(const string& dir) {
bool TWExclude::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) {
bool TWExclude::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) {
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()) {
+6 −17
Original line number Diff line number Diff line
/*
        Copyright 2013 TeamWin
        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
@@ -16,39 +16,28 @@
        along with TWRP.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TWRPDU_HPP
#define TWRPDU_HPP

#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <fstream>
#ifndef TWEXCLUDE_HPP
#define TWEXCLUDE_HPP

#include <string>
#include <vector>
#include "twcommon.h"

using namespace std;

class twrpDU {
class TWExclude {

public:
	twrpDU();
	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);
	vector<string> get_absolute_dirs(void);
	void clear_relative_dir(string dir);
private:
	vector<string> absolutedir;
	vector<string> relativedir;
};

extern twrpDU du;
#endif
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

#include <stdio.h>
#include <stdlib.h>

#include <sys/stat.h>
#include <string>

extern "C" {
Loading