]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
com_add(): Always check the return value of send_va_buffer().
authorAndre Noll <maan@systemlinux.org>
Mon, 1 Oct 2007 21:34:39 +0000 (23:34 +0200)
committerAndre Noll <maan@systemlinux.org>
Mon, 1 Oct 2007 21:34:39 +0000 (23:34 +0200)
And abort on send errors.

aft.c

diff --git a/aft.c b/aft.c
index 99b132dd9d249a9991805068161fc1faf729ada5..cbea5eb1593a1ed8f0fdaa02de634a9e1f0e92e9 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1566,8 +1566,13 @@ static int add_one_audio_file(const char *arg, const void *private_data)
        if (ret < 0)
                goto out_free;
        ret = guess_audio_format(path);
        if (ret < 0)
                goto out_free;
        ret = guess_audio_format(path);
-       if (ret < 0 && !(pad->flags & ADD_FLAG_ALL))
+       if (ret < 0 && !(pad->flags & ADD_FLAG_ALL)) {
+               if (pad->flags & ADD_FLAG_VERBOSE)
+                       ret = send_va_buffer(pad->fd, "%s: %s\n",
+                               PARA_STRERROR(-ret), path);
+               ret = 1;
                goto out_free;
                goto out_free;
+       }
        query.data = path;
        query.size = strlen(path) + 1;
        ret = send_callback_request(path_brother_callback, &query, &result);
        query.data = path;
        query.size = strlen(path) + 1;
        ret = send_callback_request(path_brother_callback, &query, &result);
@@ -1618,8 +1623,11 @@ static int add_one_audio_file(const char *arg, const void *private_data)
                format_num = ret;
                afhi_ptr = &afhi;
        }
                format_num = ret;
                afhi_ptr = &afhi;
        }
-       if (pad->flags & ADD_FLAG_VERBOSE)
-               send_va_buffer(pad->fd, "adding %s\n", path);
+       if (pad->flags & ADD_FLAG_VERBOSE) {
+               ret = send_va_buffer(pad->fd, "adding %s\n", path);
+               if (ret < 0)
+                       goto out_unmap;
+       }
        munmap(map.data, map.size);
        save_audio_file_info(hash, path, afhi_ptr, pad->flags, format_num, &obj);
        /* Ask afs to consider this entry for adding. */
        munmap(map.data, map.size);
        save_audio_file_info(hash, path, afhi_ptr, pad->flags, format_num, &obj);
        /* Ask afs to consider this entry for adding. */
@@ -1629,14 +1637,15 @@ static int add_one_audio_file(const char *arg, const void *private_data)
 out_unmap:
        munmap(map.data, map.size);
 out_free:
 out_unmap:
        munmap(map.data, map.size);
 out_free:
-       if (ret < 0)
+       if (ret < 0 && ret != -E_SEND)
                send_va_buffer(pad->fd, "failed to add %s (%s)\n", path?
                        path : arg, PARA_STRERROR(-ret));
        free(obj.data);
        free(path);
        if (afhi_ptr)
                free(afhi_ptr->chunk_table);
                send_va_buffer(pad->fd, "failed to add %s (%s)\n", path?
                        path : arg, PARA_STRERROR(-ret));
        free(obj.data);
        free(path);
        if (afhi_ptr)
                free(afhi_ptr->chunk_table);
-       return 1; /* it's not an error if not all files could be added */
+       /* it's not an error if not all files could be added */
+       return ret == -E_SEND? ret : 1;
 }
 
 int com_add(int fd, int argc, char * const * const argv)
 }
 
 int com_add(int fd, int argc, char * const * const argv)
@@ -1681,12 +1690,18 @@ int com_add(int fd, int argc, char * const * const argv)
                if (ret < 0)
                        PARA_NOTICE_LOG("failed to stat %s (%s)", path,
                                strerror(errno));
                if (ret < 0)
                        PARA_NOTICE_LOG("failed to stat %s (%s)", path,
                                strerror(errno));
-               else
+               else {
                        if (S_ISDIR(statbuf.st_mode))
                        if (S_ISDIR(statbuf.st_mode))
-                               for_each_file_in_dir(path, add_one_audio_file,
+                               ret = for_each_file_in_dir(path, add_one_audio_file,
                                        &pad);
                        else
                                        &pad);
                        else
-                               add_one_audio_file(path, &pad);
+                               ret = add_one_audio_file(path, &pad);
+                       if (ret < 0) {
+                               send_va_buffer(fd, "%s: %s\n", path, PARA_STRERROR(-ret));
+                               free(path);
+                               return ret;
+                       }
+               }
                free(path);
        }
        ret = 1;
                free(path);
        }
        ret = 1;