summaryrefslogtreecommitdiffstats
path: root/twrpTar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'twrpTar.cpp')
-rw-r--r--twrpTar.cpp43
1 files changed, 21 insertions, 22 deletions
diff --git a/twrpTar.cpp b/twrpTar.cpp
index a27374abf..2b8cd7dc4 100644
--- a/twrpTar.cpp
+++ b/twrpTar.cpp
@@ -114,7 +114,7 @@ int twrpTar::createTarFork() {
continue; // Skip /data/media
if (de->d_type == DT_BLK || de->d_type == DT_CHR)
continue;
- if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) {
+ if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0 && strcmp(de->d_name, "lost+found") != 0) {
item_len = strlen(de->d_name);
if (userdata_encryption && ((item_len >= 3 && strncmp(de->d_name, "app", 3) == 0) || (item_len >= 6 && strncmp(de->d_name, "dalvik", 6) == 0))) {
if (Generate_TarList(FileName, &RegularList, &target_size, &regular_thread_id) < 0) {
@@ -158,7 +158,7 @@ int twrpTar::createTarFork() {
continue; // Skip /data/media
if (de->d_type == DT_BLK || de->d_type == DT_CHR)
continue;
- if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) {
+ if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0 && strcmp(de->d_name, "lost+found") != 0) {
item_len = strlen(de->d_name);
if (userdata_encryption && ((item_len >= 3 && strncmp(de->d_name, "app", 3) == 0) || (item_len >= 6 && strncmp(de->d_name, "dalvik", 6) == 0))) {
// Do nothing, we added these to RegularList earlier
@@ -471,7 +471,7 @@ int twrpTar::Generate_TarList(string Path, std::vector<TarListStruct> *TarList,
continue;
TarItem.fn = FileName;
TarItem.thread_id = *thread_id;
- if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) {
+ if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0 && strcmp(de->d_name, "lost+found") != 0) {
TarList->push_back(TarItem);
if (Generate_TarList(FileName, TarList, Target_Size, thread_id) < 0)
return -1;
@@ -531,7 +531,7 @@ int twrpTar::Generate_Multiple_Archives(string Path) {
continue; // Skip /data/media
if (de->d_type == DT_BLK || de->d_type == DT_CHR)
continue;
- if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0)
+ if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0 && strcmp(de->d_name, "lost+foud") != 0)
{
unsigned long long folder_size = TWFunc::Get_Folder_Size(FileName, false);
if (Archive_Current_Size + folder_size > MAX_ARCHIVE_SIZE) {
@@ -666,7 +666,7 @@ int twrpTar::tarDirs(bool include_root) {
bool skip;
d = opendir(tardir.c_str());
- if (d != NULL) {
+ if (d != NULL) {
if (!tarexclude.empty()) {
strcpy(excl, tarexclude.c_str());
split = TWFunc::split_string(tarexclude, ' ', true);
@@ -676,7 +676,7 @@ int twrpTar::tarDirs(bool include_root) {
#ifdef RECOVERY_SDCARD_ON_DATA
if ((tardir == "/data" || tardir == "/data/") && strcmp(de->d_name, "media") == 0) continue;
#endif
- if (de->d_type == DT_BLK || de->d_type == DT_CHR || strcmp(de->d_name, "..") == 0)
+ if (de->d_type == DT_BLK || de->d_type == DT_CHR || strcmp(de->d_name, "..") == 0 || strcmp(de->d_name, "lost+found") == 0)
continue;
// Skip excluded stuff
@@ -840,10 +840,10 @@ void* twrpTar::extractMulti(void *cookie) {
int twrpTar::addFilesToExistingTar(vector <string> files, string fn) {
char* charTarFile = (char*) fn.c_str();
- if (tar_open(&t, charTarFile, NULL, O_RDONLY | O_LARGEFILE, 0644, TAR_GNU) == -1)
+ if (tar_open(&t, charTarFile, NULL, O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TAR_GNU) == -1)
return -1;
removeEOT(charTarFile);
- if (tar_open(&t, charTarFile, NULL, O_WRONLY | O_APPEND | O_LARGEFILE, 0644, TAR_GNU) == -1)
+ if (tar_open(&t, charTarFile, NULL, O_WRONLY | O_APPEND | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TAR_GNU) == -1)
return -1;
for (unsigned int i = 0; i < files.size(); ++i) {
char* file = (char*) files.at(i).c_str();
@@ -910,7 +910,7 @@ int twrpTar::createTar() {
return -1;
} else if (oaes_pid == 0) {
// openaes Child
- int output_fd = open(tarfn.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ int output_fd = open(tarfn.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (output_fd < 0) {
LOGERR("Failed to open '%s'\n", tarfn.c_str());
for (i = 0; i < 4; i++)
@@ -936,7 +936,7 @@ int twrpTar::createTar() {
close(pipes[2]);
close(pipes[3]);
fd = pipes[1];
- if(tar_fdopen(&t, fd, charRootDir, NULL, O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, 0644, TAR_GNU) != 0) {
+ if(tar_fdopen(&t, fd, charRootDir, NULL, O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TAR_GNU) != 0) {
close(fd);
LOGERR("tar_fdopen failed\n");
return -1;
@@ -964,7 +964,7 @@ int twrpTar::createTar() {
} else if (pigz_pid == 0) {
// Child
close(pigzfd[1]); // close unused output pipe
- int output_fd = open(tarfn.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ int output_fd = open(tarfn.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (output_fd < 0) {
LOGERR("Failed to open '%s'\n", tarfn.c_str());
close(pigzfd[0]);
@@ -982,7 +982,7 @@ int twrpTar::createTar() {
// Parent
close(pigzfd[0]); // close parent input
fd = pigzfd[1]; // copy parent output
- if(tar_fdopen(&t, fd, charRootDir, NULL, O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, 0644, TAR_GNU) != 0) {
+ if(tar_fdopen(&t, fd, charRootDir, NULL, O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TAR_GNU) != 0) {
close(fd);
LOGERR("tar_fdopen failed\n");
return -1;
@@ -1005,7 +1005,7 @@ int twrpTar::createTar() {
} else if (oaes_pid == 0) {
// Child
close(oaesfd[1]); // close unused
- int output_fd = open(tarfn.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ int output_fd = open(tarfn.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (output_fd < 0) {
LOGERR("Failed to open '%s'\n", tarfn.c_str());
_exit(-1);
@@ -1022,7 +1022,7 @@ int twrpTar::createTar() {
// Parent
close(oaesfd[0]); // close parent input
fd = oaesfd[1]; // copy parent output
- if(tar_fdopen(&t, fd, charRootDir, NULL, O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, 0644, TAR_GNU) != 0) {
+ if(tar_fdopen(&t, fd, charRootDir, NULL, O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TAR_GNU) != 0) {
close(fd);
LOGERR("tar_fdopen failed\n");
return -1;
@@ -1032,7 +1032,7 @@ int twrpTar::createTar() {
} else {
// Not compressed or encrypted
init_libtar_buffer(0);
- if (tar_open(&t, charTarFile, &type, O_WRONLY | O_CREAT | O_LARGEFILE, 0644, TAR_GNU) == -1) {
+ if (tar_open(&t, charTarFile, &type, O_WRONLY | O_CREAT | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TAR_GNU) == -1) {
LOGERR("tar_open error opening '%s'\n", tarfn.c_str());
return -1;
}
@@ -1115,7 +1115,7 @@ int twrpTar::openTar() {
close(pipes[1]);
close(pipes[3]);
fd = pipes[2];
- if(tar_fdopen(&t, fd, charRootDir, NULL, O_RDONLY | O_LARGEFILE, 0644, TAR_GNU) != 0) {
+ if(tar_fdopen(&t, fd, charRootDir, NULL, O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TAR_GNU) != 0) {
close(fd);
LOGERR("tar_fdopen failed\n");
return -1;
@@ -1156,7 +1156,7 @@ int twrpTar::openTar() {
// Parent
close(oaesfd[1]); // close parent output
fd = oaesfd[0]; // copy parent input
- if(tar_fdopen(&t, fd, charRootDir, NULL, O_RDONLY | O_LARGEFILE, 0644, TAR_GNU) != 0) {
+ if(tar_fdopen(&t, fd, charRootDir, NULL, O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TAR_GNU) != 0) {
close(fd);
LOGERR("tar_fdopen failed\n");
return -1;
@@ -1193,13 +1193,13 @@ int twrpTar::openTar() {
// Parent
close(pigzfd[1]); // close parent output
fd = pigzfd[0]; // copy parent input
- if(tar_fdopen(&t, fd, charRootDir, NULL, O_RDONLY | O_LARGEFILE, 0644, TAR_GNU) != 0) {
+ if(tar_fdopen(&t, fd, charRootDir, NULL, O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TAR_GNU) != 0) {
close(fd);
LOGERR("tar_fdopen failed\n");
return -1;
}
}
- } else if (tar_open(&t, charTarFile, NULL, O_RDONLY | O_LARGEFILE, 0644, TAR_GNU) != 0) {
+ } else if (tar_open(&t, charTarFile, NULL, O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TAR_GNU) != 0) {
LOGERR("Unable to open tar archive '%s'\n", charTarFile);
return -1;
}
@@ -1251,7 +1251,7 @@ int twrpTar::closeTar() {
LOGERR("Unable to close tar archive: '%s'\n", tarfn.c_str());
return -1;
}
- if (Archive_Current_Type > 1) {
+ if (Archive_Current_Type > 0) {
close(fd);
int status;
if (pigz_pid > 0 && TWFunc::Wait_For_Child(pigz_pid, &status, "pigz") != 0)
@@ -1260,7 +1260,6 @@ int twrpTar::closeTar() {
return -1;
}
free_libtar_buffer();
- TWFunc::tw_chmod(tarfn, "644");
return 0;
}
@@ -1298,7 +1297,7 @@ int twrpTar::entryExists(string entry) {
unsigned long long twrpTar::uncompressedSize() {
int type = 0;
- unsigned long long total_size = 0;
+ unsigned long long total_size = 0;
string Tar, Command, result;
vector<string> split;