Merge tag 'upstream/3.3.3'
[debian/amanda] / xfer-src / xfer.c
index 5f7a6fbe27a2e35716a01f4bbdf1f8ca35a03925..bc40cf343297a3dbf6831c5e3e1fd8c01f386cf2 100644 (file)
@@ -1,9 +1,10 @@
 /*
- * Copyright (c) 2008, 2009, 2010 Zmanda, Inc.  All Rights Reserved.
+ * Copyright (c) 2008-2012 Zmanda, Inc.  All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published
- * by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -178,7 +179,9 @@ xfer_repr(
 
 void
 xfer_start(
-    Xfer *xfer)
+    Xfer *xfer,
+    gint64 offset G_GNUC_UNUSED,
+    gint64 size)
 {
     unsigned int len;
     unsigned int i;
@@ -187,6 +190,7 @@ xfer_start(
     g_assert(xfer != NULL);
     g_assert(xfer->status == XFER_INIT);
     g_assert(xfer->elements->len >= 2);
+    g_assert(offset == 0);
 
     g_debug("Starting %s", xfer_repr(xfer));
     /* set the status to XFER_START and add a reference to our count, so that
@@ -228,6 +232,12 @@ xfer_start(
                elt->downstream = g_ptr_array_index(xfer->elements, i+1);
        }
 
+       /* Set size for first element */
+       if (size) {
+           XferElement *xe = (XferElement *)g_ptr_array_index(xfer->elements, 0);
+           xfer_element_set_size(xe, size);
+       }
+
        /* now tell them all to start, in order from destination to source */
        for (i = xfer->elements->len; i >= 1; i--) {
            XferElement *xe = (XferElement *)g_ptr_array_index(xfer->elements, i-1);
@@ -260,7 +270,10 @@ xfer_cancel(
 {
     /* Since xfer_cancel can be called from any thread, we just send a message.
      * The action takes place when the message is received. */
-    XferElement *src = g_ptr_array_index(xfer->elements, 0);
+    XferElement *src;
+    if (xfer->cancelled > 0) return;
+    xfer->cancelled++;
+    src = g_ptr_array_index(xfer->elements, 0);
     xfer_queue_message(xfer, xmsg_new(src, XMSG_CANCEL, 0));
 }