From: alex Date: Thu, 25 Nov 2021 00:57:48 +0000 (-0800) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=045721c2f8115f9b1a8a39d178666d6cc697abe3;p=seeder ... --- diff --git a/inc/add.h b/inc/add.h index 05c0ff2..87b4025 100644 --- a/inc/add.h +++ b/inc/add.h @@ -3,10 +3,10 @@ #include +#include #include #include #include -#include #define ADD_MESSAGE_ADDING_TORRENT "adding all files in %s to torrent named %s\n" #define ADD_MESSAGE_ADDED_FILE "added file %s\n" diff --git a/inc/file.h b/inc/file.h index 2745dee..bc56fc9 100644 --- a/inc/file.h +++ b/inc/file.h @@ -9,7 +9,7 @@ #include #include -#include +#include struct file { char *name; diff --git a/inc/util.h b/inc/fs.h similarity index 90% rename from inc/util.h rename to inc/fs.h index 2329adb..e1a8312 100644 --- a/inc/util.h +++ b/inc/fs.h @@ -1,5 +1,5 @@ -#ifndef __UTIL_H_ -#define __UTIL_H_ +#ifndef __FS_H_ +#define __FS_H_ #include #include diff --git a/inc/opt.h b/inc/opt.h index c58e83e..96cc4ea 100644 --- a/inc/opt.h +++ b/inc/opt.h @@ -4,10 +4,10 @@ #include #include +#include #include #include #include -#include enum file_filters { FILE_FILTER_IGNORE_DOTFILES, diff --git a/src/fs/concat.c b/src/fs/concat.c index 3ab863a..176bcd5 100644 --- a/src/fs/concat.c +++ b/src/fs/concat.c @@ -1,4 +1,4 @@ -#include +#include char *concat(const char *a, const char *b) { int len_a, len_b; @@ -15,9 +15,17 @@ char *concat(const char *a, const char *b) { if(NULL==p) { return NULL; } strcpy(p,a); - if(a[len_a-1]!='/') { - strcat(p,"/"); + + if(a[len_a-1]=='/') { + if(b[0]=='/') { + p[len_a-1] = '\0'; + } + } else { + if(b[0]!='/') { + strcat(p,"/"); + } } + strcat(p,b); return p; diff --git a/src/fs/dir.c b/src/fs/dir.c index 747ee34..632f9c4 100644 --- a/src/fs/dir.c +++ b/src/fs/dir.c @@ -1,4 +1,4 @@ -#include +#include int is_directory(const char *path) { struct stat st; diff --git a/src/fs/file.c b/src/fs/file.c index 2ef1aba..3dd1eb9 100644 --- a/src/fs/file.c +++ b/src/fs/file.c @@ -1,4 +1,4 @@ -#include +#include int is_file(const char *path) { struct stat st; diff --git a/src/fs/filter.c b/src/fs/filter.c index 2b36b00..740643c 100644 --- a/src/fs/filter.c +++ b/src/fs/filter.c @@ -1,4 +1,4 @@ -#include +#include int file_filter_all(const char *path) { return 1; diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 7139f6d..7fbe09a 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -12,7 +12,7 @@ AM_CPPFLAGS += \ -DNDEBUG endif -check_PROGRAMS = bencode.tests block.tests file.tests hash.tests hashmap.tests torrent.tests tree.tests fs.filter.tests +check_PROGRAMS = bencode.tests block.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests torrent.tests tree.tests TESTS = $(check_PROGRAMS) if ENABLE_MEMCHECK @@ -41,6 +41,16 @@ file_tests_SOURCES = \ $(top_srcdir)/src/file.c \ $(top_srcdir)/src/hash.c +fs_concat_tests_SOURCES = \ + $(common_SOURCES) \ + fs.concat.tests.c \ + $(top_srcdir)/src/fs/concat.c + +fs_filter_tests_SOURCES = \ + $(common_SOURCES) \ + fs.filter.tests.c \ + $(top_srcdir)/src/fs/filter.c + hash_tests_SOURCES = \ $(common_SOURCES) \ hash.tests.c \ @@ -68,8 +78,3 @@ tree_tests_SOURCES = \ $(top_srcdir)/src/file.c \ $(top_srcdir)/src/hash.c \ $(top_srcdir)/src/tree.c - -fs_filter_tests_SOURCES = \ - $(common_SOURCES) \ - fs.filter.tests.c \ - $(top_srcdir)/src/fs/filter.c diff --git a/test/unit/fs.concat.tests.c b/test/unit/fs.concat.tests.c new file mode 100644 index 0000000..69c30c3 --- /dev/null +++ b/test/unit/fs.concat.tests.c @@ -0,0 +1,44 @@ +#include + +#include + +int main(); +static void concat_basic_test(); + +int main() { + setup_env(); + + concat_basic_test(); + + clean_env(); + + return EXIT_SUCCESS; +} + +static void concat_basic_test() { + char *p; + + p = concat(NULL,"test"); + assert(NULL==p); + + p = concat("test",NULL); + assert(NULL==p); + + p = concat("","test"); + assert(NULL==p); + + p = concat("tesotijset",""); + assert(NULL==p); + + p = concat("alsidfjalskdjfasdf","alsdkfjlsakdfj"); + assert(strcmp(p,"alsidfjalskdjfasdf/alsdkfjlsakdfj")==0); + free(p); + + p = concat("/asdofijsd/asdofijasdf/asodiifjasoidf/","/asdlkfjsdklf/a/sdldf/adklj"); + assert(strcmp(p,"/asdofijsd/asdofijasdf/asodiifjasoidf/asdlkfjsdklf/a/sdldf/adklj")==0); + free(p); + + p = concat("/dkjflaskdjfalksdjflkajsd","/"); + assert(strcmp(p,"/dkjflaskdjfalksdjflkajsd/")==0); + free(p); +} diff --git a/test/unit/fs.filter.tests.c b/test/unit/fs.filter.tests.c index 737c4ca..43d161b 100644 --- a/test/unit/fs.filter.tests.c +++ b/test/unit/fs.filter.tests.c @@ -1,6 +1,6 @@ #include -#include +#include int main(); static void file_filter_all_basic_tests(); @@ -17,12 +17,12 @@ int main() { return EXIT_SUCCESS; } -void file_filter_all_basic_tests() { +static void file_filter_all_basic_tests() { assert(1==file_filter_all(TEST_FILE_1)); assert(1==file_filter_all(TEST_FILE_2)); } -void file_filter_ignore_dotfiles_basic_tests() { +static void file_filter_ignore_dotfiles_basic_tests() { assert(1==file_filter_ignore_dotfiles(TEST_FILE_1)); assert(1==file_filter_ignore_dotfiles(TEST_FILE_2)); assert(-1==file_filter_ignore_dotfiles(TEST_FILE_3));