refactore symlink config

Tue, 17 Sep 2019 21:21:36 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 17 Sep 2019 21:21:36 +0200
changeset 644
a38b15061848
parent 643
5b8643cf0a2f
child 645
ad61c1654dce

refactore symlink config

dav/scfg.c file | annotate | diff | comparison | revisions
dav/scfg.h file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
--- a/dav/scfg.c	Tue Sep 17 21:06:03 2019 +0200
+++ b/dav/scfg.c	Tue Sep 17 21:21:36 2019 +0200
@@ -501,23 +501,30 @@
                         pushstrat = PUSH_STRATEGY_HASH;
                     }
                 }
-            } else if(xstreq(node->name, "symlinks")) {
-                uint32_t symlinkconfig = 0;
-                const char *delims = " ,\r\n";
-                char *cmdstr = strdup(value);
-                char *s = strtok(cmdstr, delims);
-                while(s) {
-                    if(!strcmp(s, "sync")) {
-                        symlinkconfig |= SYNC_SYMLINK_SYNC;
-                    } else if(!strcmp(s, "extern_nofollow")) {
-                        symlinkconfig |= SYNC_SYMLINK_EXTERN_NOFOLLOW;
-                    } else if(!strcmp(s, "intern_nofollow")) {
-                        symlinkconfig |= SYNC_SYMLINK_INTERN_NOFOLLOW;
-                    }
-                    s = strtok(NULL, delims);
+            } else if(xstreq(node->name, "symlink-intern")) {
+                if(!value) {
+                    print_error(node->line, "missing value");
+                } else if(xstreq(value, "sync")) {
+                    symlink |= SYNC_SYMLINK_SYNC;
+                } else if(xstreq(value, "follow")) {
+                    // nothing, default
+                } else if(xstreq(value, "ignore")) {
+                    symlink |= SYNC_SYMLINK_IGNORE_INTERN;
+                } else {
+                    print_error(node->line,
+                        "unknown value: %s\n", value);
                 }
-                free(cmdstr);
-                symlink = symlinkconfig;
+            } else if(xstreq(node->name, "symlink-extern")) {
+                if(!value) {
+                    print_error(node->line, "missing value");
+                } else if(xstreq(value, "follow")) {
+                    // nothing, default
+                } else if(xstreq(value, "ignore")) {
+                    symlink |= SYNC_SYMLINK_IGNORE_EXTERN;
+                } else {
+                    print_error(node->line,
+                        "unknown value: %s\n", value);
+                }
             } else {
                 print_error(node->line,
                         "unknown directory config element: %s\n", node->name);
--- a/dav/scfg.h	Tue Sep 17 21:06:03 2019 +0200
+++ b/dav/scfg.h	Tue Sep 17 21:21:36 2019 +0200
@@ -46,9 +46,9 @@
 #define SYNC_CMD_ARCHIVE 4
 #define SYNC_CMD_RESTORE 8
     
-#define SYNC_SYMLINK_SYNC            1
-#define SYNC_SYMLINK_EXTERN_NOFOLLOW 2
-#define SYNC_SYMLINK_INTERN_NOFOLLOW 4
+#define SYNC_SYMLINK_SYNC          1
+#define SYNC_SYMLINK_IGNORE_EXTERN 2
+#define SYNC_SYMLINK_IGNORE_INTERN 4
     
 #define DEFAULT_TAG_XATTR "tags"
 #define MACOS_TAG_XATTR "com.apple.metadata:_kMDItemUserTags"
--- a/dav/sync.c	Tue Sep 17 21:06:03 2019 +0200
+++ b/dav/sync.c	Tue Sep 17 21:21:36 2019 +0200
@@ -2683,8 +2683,8 @@
                 if(!sys_stat(file_path, &targetstat)) {
                     res->isdirectory = S_ISDIR(targetstat.st_mode);
                     
-                    int nofollowextern = (dir->symlink & SYNC_SYMLINK_EXTERN_NOFOLLOW) == SYNC_SYMLINK_EXTERN_NOFOLLOW;
-                    int nofollowintern = (dir->symlink & SYNC_SYMLINK_INTERN_NOFOLLOW) == SYNC_SYMLINK_INTERN_NOFOLLOW;
+                    int nofollowextern = (dir->symlink & SYNC_SYMLINK_IGNORE_EXTERN) == SYNC_SYMLINK_IGNORE_EXTERN;
+                    int nofollowintern = (dir->symlink & SYNC_SYMLINK_IGNORE_INTERN) == SYNC_SYMLINK_IGNORE_INTERN;
                     if(isintern && nofollowintern) {
                         skip_file = TRUE;
                     } else if(!isintern && nofollowextern) {

mercurial