--- a/dav/sync.c Tue Sep 12 21:07:54 2023 +0200 +++ b/dav/sync.c Thu Sep 14 18:11:50 2023 +0200 @@ -30,10 +30,9 @@ #include <stdlib.h> #include <string.h> #include <errno.h> -#include <unistd.h> + #include <signal.h> #include <time.h> -#include <utime.h> #include <libxml/xmlerror.h> #include <sys/types.h> #include <cx/map.h> @@ -42,7 +41,17 @@ #include <cx/list.h> #include <cx/hash_map.h> #include <cx/printf.h> -#include <dirent.h> + +#ifndef _WIN32 +// unix includes +#include <unistd.h> +#include <utime.h> +#include <pthread.h> +#else +//windows includes + +#endif + #include <math.h> @@ -63,9 +72,19 @@ #include "system.h" -#include <pthread.h> + #include <ctype.h> +#ifdef _WIN32 +#define strcasecmp _stricmp + +#ifndef S_ISDIR +#define S_ISDIR(mode) ((mode) & _S_IFMT) == _S_IFDIR +#define S_ISREG(mode) ((mode) & _S_IFMT) == _S_IFREG +#endif + +#endif + static DavContext *ctx; static int sync_shutdown = 0; @@ -299,12 +318,15 @@ memset(&act, 0, sizeof(struct sigaction)); act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); -#endif - + // prepare signal handler thread pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&mutex); pthread_t tid; +#else + int tid; + int mutex; +#endif if(!strcmp(cmd, "check") || !strcmp(cmd, "check-config")) { if(!cfgret) { @@ -432,6 +454,7 @@ sync_shutdown = 1; } +#ifndef _WIN32 static void* sighandler(void *data) { signal(SIGTERM, handlesig); signal(SIGINT, handlesig); @@ -455,6 +478,16 @@ void *data; pthread_join(tid, &data); } +#else + +int start_sighandler(int* mutex) { + return 0; +} +int stop_sighandler(int* mutex, int tid) { + return 0; +} + +#endif static char* create_local_path(SyncDirectory *dir, const char *path) { char *local_path = util_concat_path(dir->path, path); @@ -1364,6 +1397,11 @@ local->size = s->st_size; } +#ifdef _WIN32 +#define fseeko fseek +#define ftello ftell +#endif + static CxList* sync_download_changed_parts( DavResource *res, LocalResource *local, @@ -1666,7 +1704,7 @@ if(issplit || (SYNC_HASHING(dir) && !link)) { if(truncate_file >= 0) { // only true if issplit is true - if(truncate(local_path, truncate_file)) { + if(sys_truncate(local_path, truncate_file)) { perror("truncate"); } } @@ -3055,10 +3093,10 @@ // therefore we remove the .lnk extension from the file name // change res->path // we only do this, if there isn't any other file with this name - sstr_t fpath = sstr(file_path); - sstr_t rpath = sstr(path); + cxstring fpath = cx_str(file_path); + cxstring rpath = cx_str(path); // remove last 4 chars (.lnk) - sstr_t new_file_path = sstrdup(sstrsubsl(fpath, 0 , fpath.length-4)); + cxmutstr new_file_path = cx_strdup(cx_strsubsl(fpath, 0 , fpath.length-4)); // check if a file with this name exists SYS_STAT nfp_s; if(!sys_stat(new_file_path.ptr, &nfp_s)) { @@ -3067,7 +3105,7 @@ free(lnkbuf); lnkbuf = NULL; } else { - sstr_t new_path = sstrdup(sstrsubsl(rpath, 0, rpath.length-4)); + cxmutstr new_path = cx_strdup(cx_strsubsl(rpath, 0, rpath.length-4)); res->local_path = res->path; res->path = new_path.ptr; // remove .lnk ext from resource path } @@ -3410,7 +3448,7 @@ #ifdef SYS_LINK_EXT // on Windows, add .lnk extension to links if(dav_get_property_ns(res, DAV_PROPS_NS, "link")) { - return ucx_sprintf("%s%s", res->path, SYS_LINK_EXT).ptr; + return cx_asprintf("%s%s", res->path, SYS_LINK_EXT).ptr; } else { // not a link return strdup(res->path); @@ -3563,6 +3601,8 @@ FileInfo f; finfo_get_values(fileinfo, &f); if((dir->metadata & FINFO_MTIME) == FINFO_MTIME && f.date_set) { + // TODO: implement on windows +#ifndef _WIN32 // set mtime struct utimbuf t; t.actime = f.last_modified; @@ -3573,6 +3613,9 @@ } else { local->last_modified = f.last_modified; } +#else + local->last_modified = 0; +#endif } if((dir->metadata & FINFO_MODE) == FINFO_MODE && f.mode_set) { // set mode