adds more fs abstraction

Sun, 10 Jun 2018 13:22:04 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 10 Jun 2018 13:22:04 +0200
changeset 412
dc74f736aea1
parent 411
a182e503617b
child 413
241db665477a

adds more fs abstraction

dav/main.c file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
dav/system.c file | annotate | diff | comparison | revisions
dav/system.h file | annotate | diff | comparison | revisions
dav/version.h file | annotate | diff | comparison | revisions
mingw.mk file | annotate | diff | comparison | revisions
--- a/dav/main.c	Sun Jun 10 12:35:00 2018 +0200
+++ b/dav/main.c	Sun Jun 10 13:22:04 2018 +0200
@@ -878,8 +878,7 @@
     if(res->iscollection) {
         printf("get: %s\n", res->path);
         
-        mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
-        int ret = util_mkdir(out, mode);
+        int ret = sys_mkdir(out);
         if(ret != 0 && errno != EEXIST) {
             fprintf(stderr, "Cannot create directory '%s': ", out);
             perror("");
--- a/dav/sync.c	Sun Jun 10 12:35:00 2018 +0200
+++ b/dav/sync.c	Sun Jun 10 13:22:04 2018 +0200
@@ -345,7 +345,6 @@
         fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
         return -1;
     }
-    
     // if there are syntax errors in the command line, fail asap.
     SyncTagFilter* tagfilter = parse_tagfilter_string(cmd_getoption(a, "tags"));
     if (!tagfilter) {
@@ -661,8 +660,7 @@
     int ret = 0;
     char *tmp_path = create_tmp_download_path(local_path);
     if(res->iscollection) {
-        mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
-        if(util_mkdir(local_path, mode) && errno != EEXIST) {
+        if(sys_mkdir(local_path) && errno != EEXIST) {
             ret = -1;
         }
         
@@ -741,7 +739,7 @@
             local->size = s.st_size;
             local->skipped = FALSE;
         } else {
-            if(unlink(tmp_path)) {
+            if(sys_unlink(tmp_path)) {
                 fprintf(stderr, "Cannot remove tmp file: %s\n", tmp_path);
             }
         }
@@ -774,7 +772,7 @@
     int ret = 0;
     if(dir->trash) {
         move_to_trash(dir, local_path);
-    } else if(unlink(local_path)) {
+    } else if(sys_unlink(local_path)) {
         fprintf(stderr, "Cannot remove file %s\n", local_path);
         ret = -2;
     }
@@ -1999,7 +1997,7 @@
     UCX_MAP_FOREACH(key, res, i) {
         printf("delete: %s\n", res->path);
         char *path = util_concat_path(dir->path, res->path);
-        if(unlink(path)) {
+        if(sys_unlink(path)) {
             if(errno != ENOENT) {
                 perror("unlink");
                 num_err++;
@@ -2204,7 +2202,7 @@
                 perror("rmdir");
             }
         } else {
-            if(unlink(path)) {
+            if(sys_unlink(path)) {
                 perror("unlink");
             }
         }
--- a/dav/system.c	Sun Jun 10 12:35:00 2018 +0200
+++ b/dav/system.c	Sun Jun 10 13:22:04 2018 +0200
@@ -89,6 +89,12 @@
     return rename(oldpath, newpath);
 }
 
+int sys_unlink(const char *path) {
+    return unlink(path);
+}
+
+int sys_mkdir(const char *path) {
+    return mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
 
 #else
 /* ---------- Windows implementation ---------- */
@@ -215,7 +221,7 @@
 
 int sys_rename(const char *oldpath, const char *newpath) {
     wchar_t *o = path2winpath(oldpath, FALSE, NULL);
-    wchara_t *n = path2winpath(newpath, FALSE, NULL);
+    wchar_t *n = path2winpath(newpath, FALSE, NULL);
     if(!o || !n) {
         return -1;
     }
@@ -233,4 +239,26 @@
     return ret;
 }
 
+int sys_unlink(const char *path) {
+    wchar_t *wpath = path2winpath(path, FALSE, NULL);
+    if(!wpath) {
+        fprintf(stderr, "sys_unlink: cannot convert path\n");
+        return -1;
+    }
+    int ret = _wunlink(wpath);
+    free(wpath);
+    return ret;
+}
+
+int sys_mkdir(const char *path) {
+    wchar_t *wpath = path2winpath(path, FALSE, NULL);
+    if(!wpath) {
+        fprintf(stderr, "sys_mkdir: cannot convert path\n");
+        return -1;
+    }
+    int ret = _wmkdir(wpath);
+    free(wpath);
+    return ret;
+}
+
 #endif
\ No newline at end of file
--- a/dav/system.h	Sun Jun 10 12:35:00 2018 +0200
+++ b/dav/system.h	Sun Jun 10 13:22:04 2018 +0200
@@ -78,6 +78,8 @@
 int sys_stat(const char *path, SYS_STAT *s);
 
 int sys_rename(const char *oldpath, const char *newpath);
+int sys_unlink(const char *path);
+int sys_mkdir(const char *path);
 
 #ifdef __cplusplus
 }
--- a/dav/version.h	Sun Jun 10 12:35:00 2018 +0200
+++ b/dav/version.h	Sun Jun 10 13:22:04 2018 +0200
@@ -27,6 +27,6 @@
  */
 
 #ifndef DAV_VERSION
-#define DAV_VERSION "1.2 RC2"
+#define DAV_VERSION "1.2 RC3"
 #endif
 
--- a/mingw.mk	Sun Jun 10 12:35:00 2018 +0200
+++ b/mingw.mk	Sun Jun 10 13:22:04 2018 +0200
@@ -31,7 +31,7 @@
 AR = ar
 RM = rm
 
-CFLAGS  = -std=gnu99 -O2 -c 
+CFLAGS  = -std=gnu99 -g -c 
 COFLAGS = -o
 LDFLAGS = 
 LOFLAGS = -o

mercurial