diff options
author | Dees_Troy <dees_troy@teamw.in> | 2013-05-04 14:39:56 +0200 |
---|---|---|
committer | Dees_Troy <dees_troy@yahoo.com> | 2013-06-22 23:16:55 +0200 |
commit | 83bd483f3db1df4b69c1612030e1a1be05b303ad (patch) | |
tree | d5c7b468b831244bfcd90aadda98b9d359d0d280 /libtar | |
parent | Fix building of updater binary (diff) | |
download | android_bootable_recovery-83bd483f3db1df4b69c1612030e1a1be05b303ad.tar android_bootable_recovery-83bd483f3db1df4b69c1612030e1a1be05b303ad.tar.gz android_bootable_recovery-83bd483f3db1df4b69c1612030e1a1be05b303ad.tar.bz2 android_bootable_recovery-83bd483f3db1df4b69c1612030e1a1be05b303ad.tar.lz android_bootable_recovery-83bd483f3db1df4b69c1612030e1a1be05b303ad.tar.xz android_bootable_recovery-83bd483f3db1df4b69c1612030e1a1be05b303ad.tar.zst android_bootable_recovery-83bd483f3db1df4b69c1612030e1a1be05b303ad.zip |
Diffstat (limited to 'libtar')
-rw-r--r-- | libtar/libtar.h | 2 | ||||
-rw-r--r-- | libtar/wrapper.c | 100 |
2 files changed, 67 insertions, 35 deletions
diff --git a/libtar/libtar.h b/libtar/libtar.h index 1d6c1dfc8..e7a355a85 100644 --- a/libtar/libtar.h +++ b/libtar/libtar.h @@ -289,7 +289,7 @@ int tar_extract_glob(TAR *t, char *globname, char *prefix); int tar_extract_all(TAR *t, char *prefix); /* add a whole tree of files */ -int tar_append_tree(TAR *t, char *realdir, char *savedir); +int tar_append_tree(TAR *t, char *realdir, char *savedir, char *exclude); /* find an entry */ int tar_find(TAR *t, char *searchstr); diff --git a/libtar/wrapper.c b/libtar/wrapper.c index 7f65375a0..0673244f5 100644 --- a/libtar/wrapper.c +++ b/libtar/wrapper.c @@ -17,7 +17,7 @@ #include <sys/param.h> #include <dirent.h> #include <errno.h> - +#include <stdlib.h> #ifdef STDC_HEADERS # include <string.h> #endif @@ -94,62 +94,94 @@ tar_extract_all(TAR *t, char *prefix) int -tar_append_tree(TAR *t, char *realdir, char *savedir) +tar_append_tree(TAR *t, char *realdir, char *savedir, char *exclude) { - char realpath[MAXPATHLEN]; - char savepath[MAXPATHLEN]; - struct dirent *dent; - DIR *dp; - struct stat s; - #ifdef DEBUG printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n", - t, realdir, (savedir ? savedir : "[NULL]")); + (long unsigned int)t, realdir, (savedir ? savedir : "[NULL]")); #endif - if (tar_append_file(t, realdir, savedir) != 0) - return -1; + char temp[1024]; + int skip = 0, i, n_spaces = 0; + char ** excluded = NULL; + char * p = NULL; + if (exclude) { + strcpy(temp, exclude); + p = strtok(exclude, " "); + if (p == NULL) { + excluded = realloc(excluded, sizeof(char*) * (++n_spaces)); + excluded[0] = temp; + } else { + while (p) { + excluded = realloc(excluded, sizeof(char*) * (++n_spaces)); + excluded[n_spaces-1] = p; + p = strtok(NULL, " "); + } + } + excluded = realloc(excluded, sizeof(char*) * (n_spaces+1)); + excluded[n_spaces] = 0; + for (i = 0; i < (n_spaces+1); i++) { + if (realdir == excluded[i]) { + printf(" excluding '%s'\n", excluded[i]); + skip = 1; + break; + } + } + } + if (skip == 0) { + if (tar_append_file(t, realdir, savedir) != 0) + return -1; + } -#ifdef DEBUG - puts(" tar_append_tree(): done with tar_append_file()..."); -#endif + char realpath[MAXPATHLEN]; + char savepath[MAXPATHLEN]; + struct dirent *dent; + DIR *dp; + struct stat s; dp = opendir(realdir); - if (dp == NULL) - { + if (dp == NULL) { if (errno == ENOTDIR) return 0; return -1; } - while ((dent = readdir(dp)) != NULL) - { - if (strcmp(dent->d_name, ".") == 0 || - strcmp(dent->d_name, "..") == 0) + while ((dent = readdir(dp)) != NULL) { + if(strcmp(dent->d_name, ".") == 0 + || strcmp(dent->d_name, "..") == 0) continue; - snprintf(realpath, MAXPATHLEN, "%s/%s", realdir, - dent->d_name); + 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 (omit) + continue; + } + + snprintf(realpath, MAXPATHLEN, "%s/%s", realdir, dent->d_name); if (savedir) - snprintf(savepath, MAXPATHLEN, "%s/%s", savedir, - dent->d_name); + snprintf(savepath, MAXPATHLEN, "%s/%s", savedir, dent->d_name); if (lstat(realpath, &s) != 0) return -1; - if (S_ISDIR(s.st_mode)) - { - if (tar_append_tree(t, realpath, - (savedir ? savepath : NULL)) != 0) + if (S_ISDIR(s.st_mode)) { + if (tar_append_tree(t, realpath, (savedir ? savepath : NULL), (exclude ? exclude : NULL)) != 0) + return -1; + continue; + } else { + if (tar_append_file(t, realpath, (savedir ? savepath : NULL)) != 0) return -1; continue; } - - if (tar_append_file(t, realpath, - (savedir ? savepath : NULL)) != 0) - return -1; - } - + } closedir(dp); + free(excluded); return 0; } |