]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Thu, 25 Nov 2021 00:57:48 +0000 (16:57 -0800)
committeralex <[email protected]>
Thu, 25 Nov 2021 00:57:48 +0000 (16:57 -0800)
inc/add.h
inc/file.h
inc/fs.h [moved from inc/util.h with 90% similarity]
inc/opt.h
src/fs/concat.c
src/fs/dir.c
src/fs/file.c
src/fs/filter.c
test/unit/Makefile.am
test/unit/fs.concat.tests.c [new file with mode: 0644]
test/unit/fs.filter.tests.c

index 05c0ff2bbefa08c50f9bfee2c622615125270655..87b4025d23f33b1960416187d5846273a67868d3 100644 (file)
--- a/inc/add.h
+++ b/inc/add.h
@@ -3,10 +3,10 @@
 
 #include<ftw.h>
 
+#include<fs.h>
 #include<hash.h>
 #include<hashmap.h>
 #include<log.h>
-#include<util.h>
 
 #define ADD_MESSAGE_ADDING_TORRENT "adding all files in %s to torrent named %s\n"
 #define ADD_MESSAGE_ADDED_FILE "added file %s\n"
index 2745dee4011983cf77ed66901092e959536d8b69..bc56fc9d951e4f1aebbc0c2551fd78e3df464ac1 100644 (file)
@@ -9,7 +9,7 @@
 #include<sodium.h>
 
 #include<block.h>
-#include<util.h>
+#include<fs.h>
 
 struct file {
        char *name;
similarity index 90%
rename from inc/util.h
rename to inc/fs.h
index 2329adb074b3111a0def2386bdb4e96681df93bd..e1a83127b288f2bac84fa38398fd6eda1ef5c8da 100644 (file)
+++ b/inc/fs.h
@@ -1,5 +1,5 @@
-#ifndef __UTIL_H_
-#define __UTIL_H_
+#ifndef __FS_H_
+#define __FS_H_
 
 #include<dirent.h>
 #include<stdio.h>
index c58e83e65901b57f7182842bae267ac79a269b9c..96cc4eaa15fd8342bd1ca1cc05e02fd4d83918a3 100644 (file)
--- a/inc/opt.h
+++ b/inc/opt.h
@@ -4,10 +4,10 @@
 #include<libgen.h>
 #include<string.h>
 
+#include<fs.h>
 #include<log.h>
 #include<session.h>
 #include<torrent.h>
-#include<util.h>
 
 enum file_filters {
        FILE_FILTER_IGNORE_DOTFILES,
index 3ab863a19a7a0750ae28ffea13727cc3b13ed0a6..176bcd50354bf36bc55d891844b1d5ecd784feea 100644 (file)
@@ -1,4 +1,4 @@
-#include<util.h>
+#include<fs.h>
 
 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;
index 747ee345e98e3570c6820ef9af0759033e25b592..632f9c43feae9cccb4bb940547f973790f919a57 100644 (file)
@@ -1,4 +1,4 @@
-#include<util.h>
+#include<fs.h>
 
 int is_directory(const char *path) {
        struct stat st;
index 2ef1aba68211610d6fca9345a0220c1e9322de9c..3dd1eb984b1f61955f0cd81e282e6e48a22510cb 100644 (file)
@@ -1,4 +1,4 @@
-#include<util.h>
+#include<fs.h>
 
 int is_file(const char *path) {
        struct stat st;
index 2b36b00f52ce6db6502348639098ea22c743aefe..740643cf58fd28cb38965377b52eac24fb9de8d6 100644 (file)
@@ -1,4 +1,4 @@
-#include<util.h>
+#include<fs.h>
 
 int file_filter_all(const char *path) {
        return 1;
index 7139f6d8863354595d288e7987069faa654cdde7..7fbe09ab00685c42758085f4407fc1b69c398ca5 100644 (file)
@@ -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 (file)
index 0000000..69c30c3
--- /dev/null
@@ -0,0 +1,44 @@
+#include<test_utils.h>
+
+#include<fs.h>
+
+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);
+}
index 737c4ca3cc000418187c4c517bcc9ab86072bc79..43d161b0f654be9b3818d717bbd01f51781af560 100644 (file)
@@ -1,6 +1,6 @@
 #include<test_utils.h>
 
-#include<util.h>
+#include<fs.h>
 
 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));