summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorn0d3 <koko1510@gmail.com>2013-03-06 20:14:15 +0100
committerDees_Troy <dees_troy@teamw.in>2013-03-18 18:37:28 +0100
commit3b51163329d24df073610499af4f540c2f0766ed (patch)
treeddf4f8417ff638327e16fab22a8190505d150f30
parentMerge "trying to fix md5 Change-Id: I4ec037f76aa965bc818afe924942adbe9a080b36" into twrp2.4 (diff)
downloadandroid_bootable_recovery-3b51163329d24df073610499af4f540c2f0766ed.tar
android_bootable_recovery-3b51163329d24df073610499af4f540c2f0766ed.tar.gz
android_bootable_recovery-3b51163329d24df073610499af4f540c2f0766ed.tar.bz2
android_bootable_recovery-3b51163329d24df073610499af4f540c2f0766ed.tar.lz
android_bootable_recovery-3b51163329d24df073610499af4f540c2f0766ed.tar.xz
android_bootable_recovery-3b51163329d24df073610499af4f540c2f0766ed.tar.zst
android_bootable_recovery-3b51163329d24df073610499af4f540c2f0766ed.zip
Diffstat (limited to '')
-rw-r--r--libtar/libtar.h2
-rw-r--r--libtar/wrapper.c30
-rw-r--r--twrpTar.cpp56
-rw-r--r--twrpTar.hpp2
4 files changed, 76 insertions, 14 deletions
diff --git a/libtar/libtar.h b/libtar/libtar.h
index f2f423b9b..1d6c1dfc8 100644
--- a/libtar/libtar.h
+++ b/libtar/libtar.h
@@ -291,6 +291,8 @@ int tar_extract_all(TAR *t, char *prefix);
/* add a whole tree of files */
int tar_append_tree(TAR *t, char *realdir, char *savedir);
+/* find an entry */
+int tar_find(TAR *t, char *searchstr);
#ifdef __cplusplus
}
diff --git a/libtar/wrapper.c b/libtar/wrapper.c
index 116dc28cc..7f65375a0 100644
--- a/libtar/wrapper.c
+++ b/libtar/wrapper.c
@@ -153,3 +153,33 @@ tar_append_tree(TAR *t, char *realdir, char *savedir)
return 0;
}
+
+
+int
+tar_find(TAR *t, char *searchstr)
+{
+ if (!searchstr)
+ return 0;
+
+ char *filename;
+ int i, entryfound = 0;
+#ifdef DEBUG
+ printf("==> tar_find(0x%lx, %s)\n", (long unsigned int)t, searchstr);
+#endif
+ while ((i = th_read(t)) == 0) {
+ filename = th_get_pathname(t);
+ if (fnmatch(searchstr, filename, FNM_FILE_NAME | FNM_PERIOD) == 0) {
+ entryfound++;
+#ifdef DEBUG
+ printf("Found matching entry: %s\n", filename);
+#endif
+ break;
+ }
+ }
+#ifdef DEBUG
+ if (!entryfound)
+ printf("No matching entry found.\n");
+#endif
+
+ return entryfound;
+}
diff --git a/twrpTar.cpp b/twrpTar.cpp
index dd6d5c37b..1ab1ab7d3 100644
--- a/twrpTar.cpp
+++ b/twrpTar.cpp
@@ -308,23 +308,34 @@ int twrpTar::extractTar() {
return 0;
}
+int twrpTar::getArchiveType() {
+ int type = 0;
+ string::size_type i = 0;
+ int firstbyte = 0, secondbyte = 0;
+ char header[3];
+
+ ifstream f;
+ f.open(tarfn.c_str(), ios::in | ios::binary);
+ f.get(header, 3);
+ f.close();
+ firstbyte = header[i] & 0xff;
+ secondbyte = header[++i] & 0xff;
+
+ if (firstbyte == 0x1f && secondbyte == 0x8b)
+ type = 1; // Compressed
+ else
+ type = 0; // Uncompressed
+
+ return type;
+}
+
int twrpTar::extract() {
- int len = 3;
- char header[len];
- string::size_type i = 0;
- int firstbyte = 0;
- int secondbyte = 0;
- int ret;
- ifstream f;
- f.open(tarfn.c_str(), ios::in | ios::binary);
- f.get(header, len);
- firstbyte = header[i] & 0xff;
- secondbyte = header[++i] & 0xff;
- f.close();
- if (firstbyte == 0x1f && secondbyte == 0x8b) {
+ int Archive_Current_Type = getArchiveType();
+
+ if (Archive_Current_Type == 1) {
//if you return the extractTGZ function directly, stack crashes happen
LOGI("Extracting gzipped tar\n");
- ret = extractTGZ();
+ int ret = extractTGZ();
return ret;
}
else {
@@ -580,6 +591,23 @@ int twrpTar::extractTGZ() {
return 0;
}
+int twrpTar::entryExists(string entry) {
+ char* searchstr = (char*)entry.c_str();
+ int ret;
+
+ int Archive_Current_Type = getArchiveType();
+
+ if (openTar(Archive_Current_Type) == -1)
+ ret = 0;
+ else
+ ret = tar_find(t, searchstr);
+
+ if (tar_close(t) != 0)
+ LOGI("Unable to close tar file after searching for entry '%s'.\n", entry.c_str());
+
+ return ret;
+}
+
extern "C" ssize_t write_tar(int fd, const void *buffer, size_t size) {
return (ssize_t) write_libtar_buffer(fd, buffer, size);
}
diff --git a/twrpTar.hpp b/twrpTar.hpp
index 427e6d1c3..3ee6028a5 100644
--- a/twrpTar.hpp
+++ b/twrpTar.hpp
@@ -38,6 +38,7 @@ class twrpTar {
int addFilesToExistingTar(vector <string> files, string tarFile);
int createTar();
int addFile(string fn, bool include_root);
+ int entryExists(string entry);
int closeTar(bool gzip);
int createTarGZFork();
int createTarFork();
@@ -59,6 +60,7 @@ class twrpTar {
int has_data_media;
int Archive_File_Count;
unsigned long long Archive_Current_Size;
+ int getArchiveType(); // 1 for compressed - 0 for uncompressed
TAR *t;
FILE* p;
int fd;