Merge "trying to fix md5 Change-Id: I4ec037f76aa965bc818afe924942adbe9a080b36" into twrp2.4
diff --git a/libtar/extract.c b/libtar/extract.c
index 49e7599..613e29f 100644
--- a/libtar/extract.c
+++ b/libtar/extract.c
@@ -45,6 +45,11 @@
gid = th_get_gid(t);
ut.modtime = ut.actime = th_get_mtime(t);
+#ifdef DEBUG
+ printf(" ==> setting perms: %s (mode %04o, uid %d, gid %d)\n",
+ filename, mode, uid, gid);
+#endif
+
/* change owner/group */
if (geteuid() == 0)
#ifdef HAVE_LCHOWN
@@ -109,6 +114,7 @@
if (TH_ISDIR(t))
{
+ printf("dir\n");
i = tar_extract_dir(t, realname);
if (i == 1)
i = 0;
@@ -172,10 +178,10 @@
int
tar_extract_regfile(TAR *t, char *realname)
{
- mode_t mode;
+ //mode_t mode;
size_t size;
- uid_t uid;
- gid_t gid;
+ //uid_t uid;
+ //gid_t gid;
int fdout;
int i, k;
char buf[T_BLOCKSIZE];
@@ -194,17 +200,19 @@
}
filename = (realname ? realname : th_get_pathname(t));
- mode = th_get_mode(t);
+ //mode = th_get_mode(t);
size = th_get_size(t);
- uid = th_get_uid(t);
- gid = th_get_gid(t);
+ //uid = th_get_uid(t);
+ //gid = th_get_gid(t);
if (mkdirhier(dirname(filename)) == -1)
return -1;
#ifdef DEBUG
- printf(" ==> extracting: %s (mode %04o, uid %d, gid %d, %d bytes)\n",
- filename, mode, uid, gid, size);
+ //printf(" ==> extracting: %s (mode %04o, uid %d, gid %d, %d bytes)\n",
+ // filename, mode, uid, gid, size);
+ printf(" ==> extracting: %s (file size %d bytes)\n",
+ filename, size);
#endif
fdout = open(filename, O_WRONLY | O_CREAT | O_TRUNC
#ifdef O_BINARY
@@ -468,7 +476,6 @@
{
mode_t mode;
char *filename;
- printf("filename: %s\n", filename);
if (!TH_ISDIR(t))
{
errno = EINVAL;
@@ -478,8 +485,10 @@
filename = (realname ? realname : th_get_pathname(t));
mode = th_get_mode(t);
- if (mkdirhier(dirname(filename)) == -1)
+ if (mkdirhier(dirname(filename)) == -1) {
+ printf("tar_extract_dir mkdirhier failed\n");
return -1;
+ }
#ifdef DEBUG
printf(" ==> extracting: %s (mode %04o, directory)\n", filename,
@@ -489,20 +498,9 @@
{
if (errno == EEXIST)
{
- if (chmod(filename, mode) == -1)
- {
#ifdef DEBUG
- perror("chmod()");
+ printf(" *** using existing directory");
#endif
- return -1;
- }
- else
- {
-#ifdef DEBUG
- puts(" *** using existing directory");
-#endif
- return 1;
- }
}
else
{
diff --git a/libtar/wrapper.c b/libtar/wrapper.c
index 4d82162..116dc28 100644
--- a/libtar/wrapper.c
+++ b/libtar/wrapper.c
@@ -79,7 +79,7 @@
printf(" tar_extract_all(): calling tar_extract_file(t, "
"\"%s\")\n", buf);
#endif
- printf("filename: %s\n", filename);
+ printf("item name: '%s'\n", filename);
/*
if (strcmp(filename, "/") == 0) {
printf("skipping /\n");
diff --git a/twrpTar.cpp b/twrpTar.cpp
index cf225db..dd6d5c3 100644
--- a/twrpTar.cpp
+++ b/twrpTar.cpp
@@ -215,7 +215,6 @@
if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0)
{
unsigned long long folder_size = TWFunc::Get_Folder_Size(FileName, false);
- tardir = FileName;
if (Archive_Current_Size + folder_size > MAX_ARCHIVE_SIZE) {
LOGI("Calling Generate_Multiple_Archives\n");
if (Generate_Multiple_Archives(FileName) < 0)
@@ -337,41 +336,43 @@
int twrpTar::tarDirs(bool include_root) {
DIR* d;
string mainfolder = tardir + "/", subfolder;
- char buf[1024];
- char* charTarFile = (char*) tarfn.c_str();
+ char buf[PATH_MAX];
d = opendir(tardir.c_str());
if (d != NULL) {
struct dirent* de;
while ((de = readdir(d)) != NULL) {
- LOGI("adding %s\n", de->d_name);
#ifdef RECOVERY_SDCARD_ON_DATA
if ((tardir == "/data" || tardir == "/data/") && strcmp(de->d_name, "media") == 0) continue;
- if (de->d_type == DT_BLK || de->d_type == DT_CHR)
- continue;
#endif
- if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
-
+ if (de->d_type == DT_BLK || de->d_type == DT_CHR || strcmp(de->d_name, "..") == 0)
+ continue;
subfolder = mainfolder;
- subfolder += de->d_name;
+ if (strcmp(de->d_name, ".") != 0) {
+ subfolder += de->d_name;
+ } else {
+ LOGI("adding '%s'\n", subfolder.c_str());
+ if (addFile(subfolder, include_root) != 0)
+ return -1;
+ continue;
+ }
+ LOGI("adding '%s'\n", subfolder.c_str());
strcpy(buf, subfolder.c_str());
if (de->d_type == DT_DIR) {
- if (include_root) {
- if (tar_append_tree(t, buf, NULL) != 0) {
- LOGE("Error appending '%s' to tar archive '%s'\n", buf, charTarFile);
+ char* charTarPath;
+ if (include_root) {
+ charTarPath = NULL;
+ } else {
+ string temp = Strip_Root_Dir(buf);
+ charTarPath = (char*) temp.c_str();
+ }
+ if (tar_append_tree(t, buf, charTarPath) != 0) {
+ LOGE("Error appending '%s' to tar archive '%s'\n", buf, tarfn.c_str());
return -1;
}
- } else {
- string temp = Strip_Root_Dir(buf);
- char* charTarPath = (char*) temp.c_str();
- if (tar_append_tree(t, buf, charTarPath) != 0) {
- LOGE("Error appending '%s' to tar archive '%s'\n", buf, charTarFile);
- return -1;
- }
- }
} else if (tardir != "/" && (de->d_type == DT_REG || de->d_type == DT_LNK)) {
- if (addFile(buf, include_root) != 0)
- return -1;
- }
+ if (addFile(buf, include_root) != 0)
+ return -1;
+ }
fflush(NULL);
}
closedir(d);