skip checking size on links
skip google music cache
Change-Id: I75d6fd0e17140d12cb2c6d335e8ff73a6f871aa2
diff --git a/libtar/wrapper.c b/libtar/wrapper.c
index 0673244..dab7e00 100644
--- a/libtar/wrapper.c
+++ b/libtar/wrapper.c
@@ -153,10 +153,12 @@
if (exclude) {
int omit = 0;
for (i = 0; i < (n_spaces+1); i++) {
- if (dent->d_name == excluded[i]) {
- printf(" excluding '%s'\n", excluded[i]);
- omit = 1;
- break;
+ if (excluded[i] != NULL) {
+ if (strcmp(dent->d_name, excluded[i]) == 0 || strcmp(excluded[i], realdir) == 0) {
+ printf(" excluding '%s'\n", excluded[i]);
+ omit = 1;
+ break;
+ }
}
}
if (omit)
@@ -179,7 +181,7 @@
return -1;
continue;
}
- }
+ }
closedir(dp);
free(excluded);
diff --git a/partition.cpp b/partition.cpp
index e02def0..444eb4b 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -1452,6 +1452,8 @@
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");
#ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS
DataManager::GetValue("tw_encrypt_backup", use_encryption);
if (use_encryption && Can_Encrypt_Backup) {
diff --git a/twrpTar.cpp b/twrpTar.cpp
index 2b8cd7d..5a9340a 100644
--- a/twrpTar.cpp
+++ b/twrpTar.cpp
@@ -66,7 +66,7 @@
}
void twrpTar::setexcl(string exclude) {
- tarexclude = exclude;
+ tarexclude.push_back(exclude);
}
int twrpTar::createTarFork() {
@@ -522,8 +522,9 @@
break;
}
}
- if (skip)
+ if (skip) {
continue;
+ }
}
FileName = Path + "/";
FileName += de->d_name;
@@ -550,35 +551,40 @@
else if (de->d_type == DT_REG || de->d_type == DT_LNK)
{
stat(FileName.c_str(), &st);
-
- if (Archive_Current_Size != 0 && Archive_Current_Size + st.st_size > MAX_ARCHIVE_SIZE) {
- LOGINFO("Closing tar '%s', ", tarfn.c_str());
- closeTar();
- if (TWFunc::Get_File_Size(tarfn) == 0) {
- LOGERR("Backup file size for '%s' is 0 bytes.\n", tarfn.c_str());
- return -1;
+ if (de->d_type != DT_LNK) {
+ if (Archive_Current_Size != 0 && Archive_Current_Size + st.st_size > MAX_ARCHIVE_SIZE) {
+ LOGINFO("Closing tar '%s', ", tarfn.c_str());
+ closeTar();
+ if (TWFunc::Get_File_Size(tarfn) == 0) {
+ LOGERR("Backup file size for '%s' is 0 bytes.\n", tarfn.c_str());
+ return -1;
+ }
+ Archive_File_Count++;
+ if (Archive_File_Count > 999) {
+ LOGERR("Archive count is too large!\n");
+ return -1;
+ }
+ string temp = basefn + "%03i";
+ sprintf(actual_filename, temp.c_str(), Archive_File_Count);
+ tarfn = actual_filename;
+ Archive_Current_Size = 0;
+ LOGINFO("Creating tar '%s'\n", tarfn.c_str());
+ gui_print("Creating archive %i...\n", Archive_File_Count + 1);
+ if (createTar() != 0)
+ return -1;
}
- Archive_File_Count++;
- if (Archive_File_Count > 999) {
- LOGERR("Archive count is too large!\n");
- return -1;
- }
- string temp = basefn + "%03i";
- sprintf(actual_filename, temp.c_str(), Archive_File_Count);
- tarfn = actual_filename;
- Archive_Current_Size = 0;
- LOGINFO("Creating tar '%s'\n", tarfn.c_str());
- gui_print("Creating archive %i...\n", Archive_File_Count + 1);
- if (createTar() != 0)
- return -1;
}
LOGINFO("Adding file: '%s'... ", FileName.c_str());
if (addFile(FileName, true) < 0)
return -1;
- Archive_Current_Size += st.st_size;
+ if (de->d_type != DT_LNK) {
+ Archive_Current_Size += st.st_size;
+ }
LOGINFO("added successfully, archive size: %llu\n", Archive_Current_Size);
- if (st.st_size > 2147483648LL)
- LOGERR("There is a file that is larger than 2GB in the file system\n'%s'\nThis file may not restore properly\n", FileName.c_str());
+ if (de->d_type != DT_LNK) {
+ if (st.st_size > 2147483648LL)
+ LOGERR("There is a file that is larger than 2GB in the file system\n'%s'\nThis file may not restore properly\n", FileName.c_str());
+ }
}
}
closedir(d);
@@ -589,14 +595,21 @@
{
string temp = tarfn + "%03i";
char actual_filename[255];
+ string tarsplit;
basefn = tarfn;
Archive_File_Count = 0;
Archive_Current_Size = 0;
sprintf(actual_filename, temp.c_str(), Archive_File_Count);
tarfn = actual_filename;
+
+ for (int i = 0; i < tarexclude.size(); ++i) {
+ tarsplit = tarexclude[i];
+ tarsplit += " ";
+ }
+
if (!tarexclude.empty())
- split = TWFunc::split_string(tarexclude, ' ', true);
+ split = TWFunc::split_string(tarsplit, ' ', true);
createTar();
DataManager::GetValue(TW_HAS_DATA_MEDIA, has_data_media);
gui_print("Creating archive 1...\n");
@@ -659,17 +672,23 @@
int twrpTar::tarDirs(bool include_root) {
DIR* d;
string mainfolder = tardir + "/", subfolder;
+ string tarsplit;
char buf[PATH_MAX], charTarPath[PATH_MAX];
-
- char excl[1024];
+ string excl;
string::size_type i;
bool skip;
+ //set exclude directories for libtar
+ for (int i = 0; i < tarexclude.size(); ++i) {
+ excl += tarexclude.at(i);
+ tarsplit = tarexclude.at(i);
+ excl += " ";
+ tarsplit += " ";
+ }
d = opendir(tardir.c_str());
if (d != NULL) {
- if (!tarexclude.empty()) {
- strcpy(excl, tarexclude.c_str());
- split = TWFunc::split_string(tarexclude, ' ', true);
+ if (!tarsplit.empty()) {
+ split = TWFunc::split_string(tarsplit, ' ', true);
}
struct dirent* de;
while ((de = readdir(d)) != NULL) {
@@ -689,8 +708,9 @@
break;
}
}
- if (skip)
+ if (skip) {
continue;
+ }
}
subfolder = mainfolder;
@@ -707,7 +727,7 @@
if (include_root) {
charTarPath[0] = NULL;
LOGINFO("tar_append_tree '%s' as NULL\n", buf, charTarPath);
- if (tar_append_tree(t, buf, NULL, excl) != 0) {
+ if (tar_append_tree(t, buf, NULL, &excl[0]) != 0) {
LOGERR("Error appending '%s' to tar archive '%s'\n", buf, tarfn.c_str());
return -1;
}
@@ -715,7 +735,7 @@
string temp = Strip_Root_Dir(buf);
strcpy(charTarPath, temp.c_str());
LOGINFO("tar_append_tree '%s' as '%s'\n", buf, charTarPath);
- if (tar_append_tree(t, buf, charTarPath, excl) != 0) {
+ if (tar_append_tree(t, buf, charTarPath, &excl[0]) != 0) {
LOGERR("Error appending '%s' to tar archive '%s'\n", buf, tarfn.c_str());
return -1;
}
@@ -879,7 +899,7 @@
return -1;
}
pigz_pid = fork();
-
+
if (pigz_pid < 0) {
LOGERR("pigz fork() failed\n");
for (i = 0; i < 4; i++)
@@ -902,7 +922,7 @@
} else {
// Parent
oaes_pid = fork();
-
+
if (oaes_pid < 0) {
LOGERR("openaes fork() failed\n");
for (i = 0; i < 4; i++)
@@ -955,7 +975,7 @@
return -1;
}
pigz_pid = fork();
-
+
if (pigz_pid < 0) {
LOGERR("fork() failed\n");
close(pigzfd[0]);
@@ -996,7 +1016,7 @@
int oaesfd[2];
pipe(oaesfd);
oaes_pid = fork();
-
+
if (oaes_pid < 0) {
LOGERR("fork() failed\n");
close(oaesfd[0]);
@@ -1059,7 +1079,7 @@
return -1;
}
oaes_pid = fork();
-
+
if (oaes_pid < 0) {
LOGERR("pigz fork() failed\n");
for (i = 0; i < 4; i++)
@@ -1089,7 +1109,7 @@
} else {
// Parent
pigz_pid = fork();
-
+
if (pigz_pid < 0) {
LOGERR("openaes fork() failed\n");
for (i = 0; i < 4; i++)
diff --git a/twrpTar.hpp b/twrpTar.hpp
index 88eedb5..9128ba0 100644
--- a/twrpTar.hpp
+++ b/twrpTar.hpp
@@ -51,7 +51,7 @@
void setfn(string fn);
void setdir(string dir);
unsigned long long uncompressedSize();
-
+
public:
int use_encryption;
int userdata_encryption;
@@ -91,10 +91,10 @@
string tardir;
string tarfn;
string basefn;
- string tarexclude;
+ vector <string> tarexclude;
vector<string> split;
std::vector<TarListStruct> *ItemList;
int thread_id;
-};
+};