summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Schmidt <janosch@webgods.de>2012-10-26 11:32:43 +0200
committerJan Schmidt <janosch@webgods.de>2012-10-26 12:06:34 +0200
commit15b1659b1d49675d25d34bc38cf3dfc45a7957d3 (patch)
tree06abb7084a0eb9cff160bc22cf37d6dfbb6e7dc6
parentb6b883d327572271a77c0720c5d7d18f0fbdeda0 (diff)
downloadfar-progs-15b1659b1d49675d25d34bc38cf3dfc45a7957d3.tar.gz
fssum: added excludes (-x option)
Signed-off-by: Jan Schmidt <janosch@webgods.de>
-rw-r--r--fssum.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/fssum.c b/fssum.c
index d117363..9e8cc2f 100644
--- a/fssum.c
+++ b/fssum.c
@@ -50,6 +50,8 @@
int gen_manifest = 0;
int in_manifest = 0;
char *checksum = NULL;
+char **excludes = NULL;
+int n_excludes = 0;
FILE *out_fp;
FILE *in_fp;
@@ -135,6 +137,7 @@ usage(void)
fprintf(stderr, " -[UGOAMCDE] : exclude respective field from calculation\n");
fprintf(stderr, " -n : reset all flags\n");
fprintf(stderr, " -N : set all flags\n");
+ fprintf(stderr, " -x : exclude path when building checksum (multiple ok)\n");
fprintf(stderr, " -h : this help\n\n");
fprintf(stderr, "The default field mask is ugoamCdE. If the checksum/manifest is read from a\n");
fprintf(stderr, "file, the mask is taken from there and the values given on the command line\n");
@@ -368,6 +371,7 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
int i;
int ret;
int fd;
+ int excl;
d = fdopendir(dirfd);
if (!d) {
@@ -404,7 +408,11 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
sum_init(&meta);
path = alloc(strlen(path_in) + strlen(namelist[i]) + 3);
sprintf(path, "%s/%s", path_in, namelist[i]);
-
+ for (excl = 0; excl < n_excludes; ++excl) {
+ if (strcmp(excludes[excl], path) == 0)
+ goto next;
+ }
+
ret = fchdir(dirfd);
if (ret == -1) {
perror("fchdir");
@@ -506,6 +514,7 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
}
sum_add_sum(dircs, &cs);
sum_add_sum(dircs, &meta);
+next:
free(path);
}
}
@@ -521,9 +530,11 @@ main(int argc, char *argv[])
sum_t cs;
char flagstring[sizeof(flchar)];
int i;
+ int plen;
+ int elen;
out_fp = stdout;
- while ((c = getopt(argc, argv, "heEfuUgGoOaAmMcCdDnNw:r:")) != EOF) {
+ while ((c = getopt(argc, argv, "heEfuUgGoOaAmMcCdDnNw:r:x:")) != EOF) {
switch(c) {
case 'f':
gen_manifest = 1;
@@ -572,6 +583,17 @@ main(int argc, char *argv[])
exit(-1);
}
break;
+ case 'x':
+ ++n_excludes;
+ excludes = realloc(excludes,
+ sizeof(*excludes) * n_excludes);
+ if (!excludes) {
+ fprintf(stderr,
+ "failed to alloc exclude space\n");
+ exit(-1);
+ }
+ excludes[n_excludes - 1] = optarg;
+ break;
case 'h':
case '?':
usage();
@@ -611,6 +633,18 @@ main(int argc, char *argv[])
}
path = argv[optind];
+ plen = strlen(path);
+ for (i = 0; i < n_excludes; ++i) {
+ if (strncmp(path, excludes[i], plen) != 0)
+ fprintf(stderr,
+ "warning: exclude %s outside of path %s\n",
+ excludes[i], path);
+ else
+ excludes[i] += plen;
+ elen = strlen(excludes[i]);
+ if (excludes[i][elen - 1] == '/')
+ excludes[i][elen - 1] = '\0';
+ }
fd = open(path, O_RDONLY);
if (fd == -1) {