summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Schmidt <list.btrfs@jan-o-sch.net>2013-03-21 15:03:22 +0100
committerJan Schmidt <list.btrfs@jan-o-sch.net>2013-03-21 15:10:34 +0100
commitcb849f6679d502e2728c0190cdb8bd0c52b277ce (patch)
tree857e1f4beacc774692d14d34be795ad49b4bd0a3
parentaa79fbf38bf0feb54e874f0c7e22a67d4d195207 (diff)
downloadfar-progs-cb849f6679d502e2728c0190cdb8bd0c52b277ce.tar.gz
fssum: fix -x treatment when path has a trailing '/'
-rw-r--r--fssum.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/fssum.c b/fssum.c
index bc641a1..6749029 100644
--- a/fssum.c
+++ b/fssum.c
@@ -47,10 +47,15 @@
/* TODO: add hardlink recognition */
/* TODO: add xattr/acl */
+struct excludes {
+ char *path;
+ int len;
+};
+
int gen_manifest = 0;
int in_manifest = 0;
char *checksum = NULL;
-char **excludes = NULL;
+struct excludes *excludes;
int n_excludes = 0;
FILE *out_fp;
FILE *in_fp;
@@ -137,7 +142,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, " -x path : 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");
@@ -409,7 +414,8 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
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)
+ if (strncmp(excludes[excl].path, path,
+ excludes[excl].len) == 0)
goto next;
}
@@ -594,7 +600,7 @@ main(int argc, char *argv[])
"failed to alloc exclude space\n");
exit(-1);
}
- excludes[n_excludes - 1] = optarg;
+ excludes[n_excludes - 1].path = optarg;
break;
case 'h':
case '?':
@@ -639,16 +645,23 @@ main(int argc, char *argv[])
path = argv[optind];
plen = strlen(path);
+ if (path[plen - 1] == '/') {
+ --plen;
+ path[plen] = '\0';
+ }
+
for (i = 0; i < n_excludes; ++i) {
- if (strncmp(path, excludes[i], plen) != 0)
+ if (strncmp(path, excludes[i].path, plen) != 0)
fprintf(stderr,
"warning: exclude %s outside of path %s\n",
- excludes[i], path);
+ excludes[i].path, path);
else
- excludes[i] += plen;
- elen = strlen(excludes[i]);
- if (excludes[i][elen - 1] == '/')
- excludes[i][elen - 1] = '\0';
+ excludes[i].path += plen;
+ elen = strlen(excludes[i].path);
+ if (excludes[i].path[elen - 1] == '/')
+ --elen;
+ excludes[i].path[elen] = '\0';
+ excludes[i].len = elen;
}
fd = open(path, O_RDONLY);