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

Commit 34684ff3 authored by bigbiff bigbiff's avatar bigbiff bigbiff Committed by Dees Troy
Browse files

Create a TWRP Disk Usage Class to retain state about a directory and whether...

Create a TWRP Disk Usage Class to retain state about a directory and whether we should skip it in other classes like twrpTar.
Moved Get_Folder_Size to this new class.

Change-Id: If0a0220f900eb109581f2eeaf7b76e3f7d6886f1
parent 4d132cab
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ LOCAL_SRC_FILES := \
    twrp.cpp \
    fixPermissions.cpp \
    twrpTar.cpp \
	twrpDU.cpp \
    twrpDigest.cpp \

LOCAL_SRC_FILES += \
+14 −14
Original line number Diff line number Diff line
/*
	Copyright 2012 bigbiff/Dees_Troy TeamWin
	Copyright 2013 TeamWin
	This file is part of TWRP/TeamWin Recovery Project.

	TWRP is free software: you can redistribute it and/or modify
@@ -39,6 +39,7 @@
#include "twrp-functions.hpp"
#include "twrpDigest.hpp"
#include "twrpTar.hpp"
#include "twrpDU.hpp"
extern "C" {
	#include "mtdutils/mtdutils.h"
	#include "mtdutils/mounts.h"
@@ -1555,7 +1556,10 @@ bool TWPartition::Backup_Tar(string backup_folder) {
	DataManager::GetValue(TW_USE_COMPRESSION_VAR, use_compression);
	tar.use_compression = use_compression;
	//exclude Google Music Cache
	tar.setexcl("/data/data/com.google.android.music/files");
	vector<string> excludedirs = du.get_absolute_dirs();
	for (int i = 0; i < excludedirs.size(); ++i) {
		tar.setexcl(excludedirs.at(i));
	}
#ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS
	DataManager::GetValue("tw_encrypt_backup", use_encryption);
	if (use_encryption && Can_Encrypt_Backup) {
@@ -1772,16 +1776,12 @@ bool TWPartition::Update_Size(bool Display_Error) {
	if (Has_Data_Media) {
		if (Mount(Display_Error)) {
			unsigned long long data_media_used, actual_data;
			Used = TWFunc::Get_Folder_Size("/data", Display_Error);
			data_media_used = TWFunc::Get_Folder_Size("/data/media", Display_Error);
			actual_data = Used - data_media_used;
			Backup_Size = actual_data;
			int bak = (int)(Backup_Size / 1048576LLU);
			int total = (int)(Size / 1048576LLU);
			int us = (int)(Used / 1048576LLU);
			du.add_relative_dir("media");
			Used = du.Get_Folder_Size("/data");
			Backup_Size = Used;
			int bak = (int)(Used / 1048576LLU);
			int fre = (int)(Free / 1048576LLU);
			int datmed = (int)(data_media_used / 1048576LLU);
			LOGINFO("Data backup size is %iMB, size: %iMB, used: %iMB, free: %iMB, in data/media: %iMB.\n", bak, total, us, fre, datmed);
			LOGINFO("Data backup size is %iMB, free: %iMB.\n", bak, fre);
		} else {
			if (!Was_Already_Mounted)
				UnMount(false);
@@ -1789,7 +1789,7 @@ bool TWPartition::Update_Size(bool Display_Error) {
		}
	} else if (Has_Android_Secure) {
		if (Mount(Display_Error))
			Backup_Size = TWFunc::Get_Folder_Size(Backup_Path, Display_Error);
			Backup_Size = du.Get_Folder_Size(Backup_Path);
		else {
			if (!Was_Already_Mounted)
				UnMount(false);
+5 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include "twrp-functions.hpp"
#include "fixPermissions.hpp"
#include "twrpDigest.hpp"
#include "twrpDU.hpp"

#ifdef TW_INCLUDE_CRYPTO
	#ifdef TW_INCLUDE_JB_CRYPTO
@@ -46,6 +47,9 @@
	#include "cutils/properties.h"
#endif

TWPartitionManager::TWPartitionManager(void) {
}

int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error) {
	FILE *fstabFile;
	char fstab_line[MAX_FSTAB_LINE_LENGTH];
@@ -772,7 +776,7 @@ int TWPartitionManager::Run_Backup(void) {

	time(&total_stop);
	int total_time = (int) difftime(total_stop, total_start);
	unsigned long long actual_backup_size = TWFunc::Get_Folder_Size(Full_Backup_Path, true);
	uint64_t actual_backup_size = du.Get_Folder_Size(Full_Backup_Path);
    actual_backup_size /= (1024LLU * 1024LLU);

	int prev_img_bps, use_compression;
+2 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@

#include <vector>
#include <string>
#include "twrpDU.hpp"

#define MAX_FSTAB_LINE_LENGTH 2048

@@ -162,7 +163,7 @@ friend class GUIPartitionList;
class TWPartitionManager
{
public:
	TWPartitionManager() {}
	TWPartitionManager();													  // Constructor for TWRPartionManager
	~TWPartitionManager() {}

public:
+0 −33
Original line number Diff line number Diff line
@@ -206,39 +206,6 @@ int TWFunc::Recursive_Mkdir(string Path) {
	return true;
}

unsigned long long TWFunc::Get_Folder_Size(const string& Path, bool Display_Error) {
	DIR* d;
	struct dirent* de;
	struct stat st;
	unsigned long long dusize = 0;
	unsigned long long dutemp = 0;

	d = opendir(Path.c_str());
	if (d == NULL)
	{
		LOGERR("error opening '%s'\n", Path.c_str());
		LOGERR("error: %s\n", strerror(errno));
		return 0;
	}

	while ((de = readdir(d)) != NULL)
	{
		if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0 && strcmp(de->d_name, "lost+found") != 0)
		{
			dutemp = Get_Folder_Size((Path + "/" + de->d_name), Display_Error);
			dusize += dutemp;
			dutemp = 0;
		}
		else if (de->d_type == DT_REG)
		{
			stat((Path + "/" + de->d_name).c_str(), &st);
			dusize += (unsigned long long)(st.st_size);
		}
	}
	closedir(d);
	return dusize;
}

bool TWFunc::Path_Exists(string Path) {
	// Check to see if the Path exists
	struct stat st;
Loading