summaryrefslogtreecommitdiffstats
path: root/libtar/wrapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'libtar/wrapper.c')
-rw-r--r--libtar/wrapper.c110
1 files changed, 39 insertions, 71 deletions
diff --git a/libtar/wrapper.c b/libtar/wrapper.c
index 82f045f7d..d3d285f44 100644
--- a/libtar/wrapper.c
+++ b/libtar/wrapper.c
@@ -10,18 +10,19 @@
** University of Illinois at Urbana-Champaign
*/
-#define DEBUG
#include <internal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/param.h>
#include <dirent.h>
#include <errno.h>
-#include <stdlib.h>
+
#ifdef STDC_HEADERS
# include <string.h>
#endif
+
int
tar_extract_glob(TAR *t, char *globname, char *prefix)
{
@@ -44,7 +45,7 @@ tar_extract_glob(TAR *t, char *globname, char *prefix)
snprintf(buf, sizeof(buf), "%s/%s", prefix, filename);
else
strlcpy(buf, filename, sizeof(buf));
- if (tar_extract_file(t, filename, prefix, &fd) != 0)
+ if (tar_extract_file(t, buf, prefix, &fd) != 0)
return -1;
}
@@ -58,11 +59,12 @@ tar_extract_all(TAR *t, char *prefix, const int *progress_fd)
char *filename;
char buf[MAXPATHLEN];
int i;
- printf("prefix: %s\n", prefix);
+
#ifdef DEBUG
printf("==> tar_extract_all(TAR *t, \"%s\")\n",
(prefix ? prefix : "(null)"));
#endif
+
while ((i = th_read(t)) == 0)
{
#ifdef DEBUG
@@ -79,105 +81,71 @@ tar_extract_all(TAR *t, char *prefix, const int *progress_fd)
printf(" tar_extract_all(): calling tar_extract_file(t, "
"\"%s\")\n", buf);
#endif
- printf("item name: '%s'\n", filename);
if (tar_extract_file(t, buf, prefix, progress_fd) != 0)
return -1;
}
+
return (i == 1 ? 0 : -1);
}
int
-tar_append_tree(TAR *t, char *realdir, char *savedir, char *exclude)
+tar_append_tree(TAR *t, char *realdir, char *savedir)
{
-#ifdef DEBUG
- printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n",
- (long unsigned int)t, realdir, (savedir ? savedir : "[NULL]"));
-#endif
-
- 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;
- }
-
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]"));
+#endif
+
+ if (tar_append_file(t, realdir, savedir) != 0)
+ return -1;
+
+#ifdef DEBUG
+ puts(" tar_append_tree(): done with tar_append_file()...");
+#endif
+
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;
- if (exclude) {
- int omit = 0;
- for (i = 0; i < (n_spaces+1); i++) {
- 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)
- continue;
- }
-
- snprintf(realpath, MAXPATHLEN, "%s/%s", realdir, dent->d_name);
+ 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), (exclude ? exclude : NULL)) != 0)
- return -1;
- continue;
- } else {
- if (tar_append_file(t, realpath, (savedir ? savepath : NULL)) != 0)
+ if (S_ISDIR(s.st_mode))
+ {
+ if (tar_append_tree(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;
}