# HG changeset patch
# User Mike Becker <universe@uap-core.de>
# Date 1513119534 -3600
# Node ID e554f3d72d9e59e57bcdb7550561b917002fff16
# Parent  76bd29a11cc9ef344daa0fac9d62fa590b2851dd
fixes infinite loop when trying to overwrite a collection with a regular file

diff -r 76bd29a11cc9 -r e554f3d72d9e dav/main.c
--- a/dav/main.c	Tue Dec 12 23:36:47 2017 +0100
+++ b/dav/main.c	Tue Dec 12 23:58:54 2017 +0100
@@ -1162,6 +1162,15 @@
     } else if(res->iscollection) {
         // TODO: free res
         char *newpath = util_concat_path(path, name);
+        
+        if (!strcmp(path, newpath)) {
+            // TODO: free res
+            fprintf(stderr, "Cannot put file, because a collection with "
+                    "that name already exists.\n");
+            free(newpath);
+            return -1;
+        }
+        
         path = newpath;
         res = dav_resource_new(sn, path);
         free(newpath);