http: fix processing server http data separated by \n instead of \r\n
[oweals/uclient.git] / uclient-fetch.c
index 010117d4909fd79df81ac4f943f348e983e040ca..d2ffde3f89423d975d38a730023d59db645c9217 100644 (file)
@@ -103,7 +103,10 @@ static int open_output_file(const char *path, uint64_t resume_offset)
        if (cur_resume)
                flags = O_RDWR;
        else
-               flags = O_WRONLY | O_EXCL;
+               flags = O_WRONLY;
+
+       if (!cur_resume && !output_file)
+               flags |= O_EXCL;
 
        flags |= O_CREAT;
 
@@ -162,12 +165,22 @@ static void header_done_cb(struct uclient *cl)
        uint64_t resume_offset = 0, resume_end, resume_size;
        static int retries;
 
-       if (retries < 10 && uclient_http_redirect(cl)) {
-               if (!quiet)
-                       fprintf(stderr, "Redirected to %s on %s\n", cl->url->location, cl->url->host);
+       if (retries < 10) {
+               int ret = uclient_http_redirect(cl);
+               if (ret < 0) {
+                       if (!quiet)
+                               fprintf(stderr, "Failed to redirect to %s on %s\n", cl->url->location, cl->url->host);
+                       error_ret = 8;
+                       request_done(cl);
+                       return;
+               }
+               if (ret > 0) {
+                       if (!quiet)
+                               fprintf(stderr, "Redirected to %s on %s\n", cl->url->location, cl->url->host);
 
-               retries++;
-               return;
+                       retries++;
+                       return;
+               }
        }
 
        if (cl->status_code == 204 && cur_resume) {