| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#define main rsync_main |
| 7 |
#include "rsync.h" |
| 8 |
#undef main |
| 9 |
|
| 10 |
#include <stdio.h> |
| 11 |
|
| 12 |
|
| 13 |
int dry_run = 0, am_root = 0, am_sender = 1, read_only = 0, list_only = 0; |
| 14 |
int copy_links = 0, copy_unsafe_links = 0; |
| 15 |
short info_levels[COUNT_INFO], debug_levels[COUNT_DEBUG]; |
| 16 |
|
| 17 |
static const struct { const char *in, *out; } cases[] = { |
| 18 |
{ "a/b/../c", "a/c" }, |
| 19 |
{ "/x/y/../z", "/x/z" }, |
| 20 |
{ "a/../b", "b" }, |
| 21 |
{ "p/q/r/../../s","p/s" }, |
| 22 |
{ "d/e/..", "d" }, |
| 23 |
}; |
| 24 |
|
| 25 |
int main(int argc, char *argv[]) |
| 26 |
{ |
| 27 |
(void)argc; (void)argv; |
| 28 |
int i, fails = 0, n = (int)(sizeof cases / sizeof cases[0]); |
| 29 |
for (i = 0; i < n; i++) { |
| 30 |
char buf[MAXPATHLEN]; |
| 31 |
strlcpy(buf, cases[i].in, sizeof buf); |
| 32 |
clean_fname(buf, CFN_COLLAPSE_DOT_DOT_DIRS); |
| 33 |
if (strcmp(buf, cases[i].out) != 0) { |
| 34 |
printf("FAIL: clean_fname(\"%s\") = \"%s\", expected \"%s\"\n", |
| 35 |
cases[i].in, buf, cases[i].out); |
| 36 |
fails++; |
| 37 |
} |
| 38 |
} |
| 39 |
if (fails) { |
| 40 |
printf("clean_fname: %d case(s) not collapsed -- CFN_COLLAPSE_DOT_DOT_DIRS " |
| 41 |
"off-by-one\n", fails); |
| 42 |
return 1; |
| 43 |
} |
| 44 |
printf("clean_fname: '..' collapse correct\n"); |
| 45 |
return 0; |
| 46 |
} |