Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Templeton <seantempleton@outlook.com>2019-02-23 06:58:40 +0300
committerSean Templeton <seantempleton@outlook.com>2019-03-04 06:43:10 +0300
commit0c122ff5506ffa94a7cb72aa857d2a6a17899f89 (patch)
treebf20110da847ea07e404278ea3ef7a444744d518 /Duplicati/Library
parent3de04da39e789438589514c25f12e5a1a54c63ff (diff)
Change IBackend and IStreamingBackend to return Task for Put()
Diffstat (limited to 'Duplicati/Library')
-rw-r--r--Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs22
-rw-r--r--Duplicati/Library/Backend/AmazonCloudDrive/AmzCD.cs20
-rw-r--r--Duplicati/Library/Backend/AzureBlob/AzureBlobBackend.cs12
-rw-r--r--Duplicati/Library/Backend/Backblaze/B2.cs20
-rw-r--r--Duplicati/Library/Backend/Box/BoxBackend.cs18
-rw-r--r--Duplicati/Library/Backend/CloudFiles/CloudFiles.cs18
-rw-r--r--Duplicati/Library/Backend/Dropbox/Dropbox.cs16
-rw-r--r--Duplicati/Library/Backend/FTP/FTPBackend.cs22
-rw-r--r--Duplicati/Library/Backend/File/FileBackend.cs21
-rw-r--r--Duplicati/Library/Backend/GoogleServices/GoogleCloudStorage.cs22
-rw-r--r--Duplicati/Library/Backend/GoogleServices/GoogleDrive.cs22
-rw-r--r--Duplicati/Library/Backend/HubiC/HubiCBackend.cs17
-rw-r--r--Duplicati/Library/Backend/Jottacloud/Jottacloud.cs16
-rw-r--r--Duplicati/Library/Backend/Mega/MegaBackend.cs20
-rw-r--r--Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs23
-rw-r--r--Duplicati/Library/Backend/OpenStack/OpenStackStorage.cs18
-rw-r--r--Duplicati/Library/Backend/Rclone/Rclone.cs20
-rw-r--r--Duplicati/Library/Backend/S3/S3Backend.cs12
-rw-r--r--Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs18
-rw-r--r--Duplicati/Library/Backend/SharePoint/SharePointBackend.cs27
-rw-r--r--Duplicati/Library/Backend/Sia/Sia.cs36
-rw-r--r--Duplicati/Library/Backend/TahoeLAFS/TahoeBackend.cs20
-rw-r--r--Duplicati/Library/Backend/WEBDAV/WEBDAV.cs17
-rw-r--r--Duplicati/Library/Interface/IBackend.cs6
-rw-r--r--Duplicati/Library/Interface/IStreamingBackend.cs8
-rw-r--r--Duplicati/Library/Main/BackendManager.cs5
-rw-r--r--Duplicati/Library/Main/Operation/Backup/BackendUploader.cs31
27 files changed, 293 insertions, 214 deletions
diff --git a/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs b/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs
index 680131057..42a13f356 100644
--- a/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs
+++ b/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs
@@ -18,17 +18,19 @@
//
#endregion
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.FtpClient;
using System.Net.Security;
using System.Security.Authentication;
-using Duplicati.Library.Interface;
-using Uri = System.Uri;
+using System.Threading;
+using System.Threading.Tasks;
using CoreUtility = Duplicati.Library.Utility.Utility;
-using Duplicati.Library.Common.IO;
-
+using Uri = System.Uri;
+
namespace Duplicati.Library.Backend.AlternativeFTP
{
// ReSharper disable once RedundantExtendsListEntry
@@ -304,7 +306,7 @@ namespace Duplicati.Library.Backend.AlternativeFTP
return list;
}
- public void Put(string remotename, System.IO.Stream input)
+ public Task Put(string remotename, System.IO.Stream input, CancellationToken cancelToken)
{
string remotePath = remotename;
long streamLen = -1;
@@ -355,7 +357,7 @@ namespace Duplicati.Library.Backend.AlternativeFTP
{
if (fileEntry.Size < 0 || streamLen < 0 || fileEntry.Size == streamLen)
{
- return;
+ return Task.FromResult(true);
}
throw new UserInformationException(Strings.ListVerifySizeFailure(remotename, fileEntry.Size, streamLen), "AftpListVerifySizeFailure");
@@ -374,13 +376,15 @@ namespace Duplicati.Library.Backend.AlternativeFTP
throw;
}
+
+ return Task.FromResult(true);
}
- public void Put(string remotename, string localname)
+ public Task Put(string remotename, string localname, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.Open(localname, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
{
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
}
@@ -485,7 +489,7 @@ namespace Duplicati.Library.Backend.AlternativeFTP
{
try
{
- Put(TEST_FILE_NAME, testStream);
+ Put(TEST_FILE_NAME, testStream, CancellationToken.None).Wait();
}
catch (Exception e)
{
diff --git a/Duplicati/Library/Backend/AmazonCloudDrive/AmzCD.cs b/Duplicati/Library/Backend/AmazonCloudDrive/AmzCD.cs
index 441eda720..3791a3e7c 100644
--- a/Duplicati/Library/Backend/AmazonCloudDrive/AmzCD.cs
+++ b/Duplicati/Library/Backend/AmazonCloudDrive/AmzCD.cs
@@ -14,15 +14,17 @@
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.Linq;
-using System.Collections.Generic;
+using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Net;
-using Duplicati.Library.Common.IO;
-
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend.AmazonCloudDrive
{
public class AmzCD : IBackend, IStreamingBackend, IRenameEnabledBackend
@@ -313,7 +315,7 @@ namespace Duplicati.Library.Backend.AmazonCloudDrive
#region IStreamingBackend implementation
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
EnforceConsistencyDelay(remotename);
@@ -362,6 +364,8 @@ namespace Duplicati.Library.Backend.AmazonCloudDrive
{
SetWaitUntil(remotename, DateTime.Now + m_delayTimeSpan);
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
@@ -428,10 +432,10 @@ namespace Duplicati.Library.Backend.AmazonCloudDrive
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
diff --git a/Duplicati/Library/Backend/AzureBlob/AzureBlobBackend.cs b/Duplicati/Library/Backend/AzureBlob/AzureBlobBackend.cs
index 176e42a6b..08b66ef43 100644
--- a/Duplicati/Library/Backend/AzureBlob/AzureBlobBackend.cs
+++ b/Duplicati/Library/Backend/AzureBlob/AzureBlobBackend.cs
@@ -18,10 +18,11 @@
//
#endregion
-using System;
+using Duplicati.Library.Interface;
using System.Collections.Generic;
using System.IO;
-using Duplicati.Library.Interface;
+using System.Threading;
+using System.Threading.Tasks;
namespace Duplicati.Library.Backend.AzureBlob
{
@@ -87,18 +88,19 @@ namespace Duplicati.Library.Backend.AzureBlob
return _azureBlob.ListContainerEntries();
}
- public void Put(string remotename, string localname)
+ public Task Put(string remotename, string localname, CancellationToken cancelToken)
{
using (var fs = File.Open(localname,
FileMode.Open, FileAccess.Read, FileShare.Read))
{
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
}
- public void Put(string remotename, Stream input)
+ public Task Put(string remotename, Stream input, CancellationToken cancelToken)
{
_azureBlob.AddFileStream(remotename, input);
+ return Task.FromResult(true);
}
public void Get(string remotename, string localname)
diff --git a/Duplicati/Library/Backend/Backblaze/B2.cs b/Duplicati/Library/Backend/Backblaze/B2.cs
index 460726da8..1ba169a05 100644
--- a/Duplicati/Library/Backend/Backblaze/B2.cs
+++ b/Duplicati/Library/Backend/Backblaze/B2.cs
@@ -14,14 +14,16 @@
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.Linq;
-using System.Collections.Generic;
-using Duplicati.Library.Utility;
-using Duplicati.Library.Interface;
using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
+using Duplicati.Library.Utility;
using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Net;
+using System.Threading;
+using System.Threading.Tasks;
namespace Duplicati.Library.Backend.Backblaze
{
@@ -188,7 +190,7 @@ namespace Duplicati.Library.Backend.Backblaze
}
}
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
TempFile tmp = null;
@@ -285,6 +287,8 @@ namespace Duplicati.Library.Backend.Backblaze
{
}
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
@@ -368,10 +372,10 @@ namespace Duplicati.Library.Backend.Backblaze
).ToList();
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
diff --git a/Duplicati/Library/Backend/Box/BoxBackend.cs b/Duplicati/Library/Backend/Box/BoxBackend.cs
index 9f2b828fc..6a68b9e24 100644
--- a/Duplicati/Library/Backend/Box/BoxBackend.cs
+++ b/Duplicati/Library/Backend/Box/BoxBackend.cs
@@ -14,13 +14,15 @@
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.Linq;
-using Duplicati.Library.Interface;
using Duplicati.Library.Common.IO;
-using System.Collections.Generic;
+using Duplicati.Library.Interface;
using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Net;
+using System.Threading;
+using System.Threading.Tasks;
namespace Duplicati.Library.Backend.Box
{
@@ -196,7 +198,7 @@ namespace Duplicati.Library.Backend.Box
#region IStreamingBackend implementation
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
var createreq = new CreateItemRequest() {
Name = remotename,
@@ -237,6 +239,8 @@ namespace Duplicati.Library.Backend.Box
m_filecache.Clear();
throw;
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
@@ -257,10 +261,10 @@ namespace Duplicati.Library.Backend.Box
select (IFileEntry)new FileEntry(n.Name, n.Size, n.ModifiedAt, n.ModifiedAt) { IsFolder = n.Type == "folder" };
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
diff --git a/Duplicati/Library/Backend/CloudFiles/CloudFiles.cs b/Duplicati/Library/Backend/CloudFiles/CloudFiles.cs
index 1519b9ecf..5ba0c9730 100644
--- a/Duplicati/Library/Backend/CloudFiles/CloudFiles.cs
+++ b/Duplicati/Library/Backend/CloudFiles/CloudFiles.cs
@@ -17,14 +17,14 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Net;
-using Duplicati.Library.Interface;
-using Duplicati.Library.Common.IO;
-
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend
{
public class CloudFiles : IBackend, IStreamingBackend
@@ -194,10 +194,10 @@ namespace Duplicati.Library.Backend
} while (repeat);
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
@@ -314,7 +314,7 @@ namespace Duplicati.Library.Backend
}
}
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
HttpWebRequest req = CreateRequest("/" + remotename, "");
req.Method = "PUT";
@@ -394,6 +394,8 @@ namespace Duplicati.Library.Backend
throw new Exception(Strings.CloudFiles.ETagVerificationError);
}
}
+
+ return Task.FromResult(true);
}
#endregion
diff --git a/Duplicati/Library/Backend/Dropbox/Dropbox.cs b/Duplicati/Library/Backend/Dropbox/Dropbox.cs
index e31c4f522..5b74eb05c 100644
--- a/Duplicati/Library/Backend/Dropbox/Dropbox.cs
+++ b/Duplicati/Library/Backend/Dropbox/Dropbox.cs
@@ -3,7 +3,9 @@ using System.Collections.Generic;
using System.IO;
using Duplicati.Library.Interface;
using Duplicati.Library.Common.IO;
-
+using System.Threading.Tasks;
+using System.Threading;
+
namespace Duplicati.Library.Backend
{
public class Dropbox : IBackend, IStreamingBackend
@@ -99,15 +101,15 @@ namespace Duplicati.Library.Backend
}
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
- using(FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename,fs);
+ using(FileStream fs = File.OpenRead(filename))
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
{
- using(FileStream fs = System.IO.File.Create(filename))
+ using(FileStream fs = File.Create(filename))
Get(remotename, fs);
}
@@ -162,7 +164,7 @@ namespace Duplicati.Library.Backend
}
}
- public void Put(string remotename, Stream stream)
+ public Task Put(string remotename, Stream stream, CancellationToken cancelToken)
{
try
{
@@ -174,6 +176,8 @@ namespace Duplicati.Library.Backend
// we can catch some events here and convert them to Duplicati exceptions
throw;
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, Stream stream)
diff --git a/Duplicati/Library/Backend/FTP/FTPBackend.cs b/Duplicati/Library/Backend/FTP/FTPBackend.cs
index 84b43f19a..f2569cf08 100644
--- a/Duplicati/Library/Backend/FTP/FTPBackend.cs
+++ b/Duplicati/Library/Backend/FTP/FTPBackend.cs
@@ -17,13 +17,15 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
using System;
using System.Collections.Generic;
-using System.Text.RegularExpressions;
-using Duplicati.Library.Interface;
using System.Linq;
-using Duplicati.Library.Common.IO;
-
+using System.Text.RegularExpressions;
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend
{
public class FTP : IBackend, IStreamingBackend
@@ -255,7 +257,7 @@ namespace Duplicati.Library.Backend
}
}
- public void Put(string remotename, System.IO.Stream input)
+ public Task Put(string remotename, System.IO.Stream input, CancellationToken cancelToken)
{
System.Net.FtpWebRequest req = null;
try
@@ -279,8 +281,8 @@ namespace Duplicati.Library.Backend
if (fe.Name.Equals(remotename) || fe.Name.EndsWith("/" + remotename, StringComparison.Ordinal) || fe.Name.EndsWith("\\" + remotename, StringComparison.Ordinal))
{
if (fe.Size < 0 || streamLen < 0 || fe.Size == streamLen)
- return;
-
+ return Task.FromResult(true);
+
throw new Exception(Strings.FTPBackend.ListVerifySizeFailure(remotename, fe.Size, streamLen));
}
@@ -295,12 +297,14 @@ namespace Duplicati.Library.Backend
else
throw;
}
+
+ return Task.FromResult(true);
}
- public void Put(string remotename, string localname)
+ public Task Put(string remotename, string localname, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.Open(localname, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, System.IO.Stream output)
diff --git a/Duplicati/Library/Backend/File/FileBackend.cs b/Duplicati/Library/Backend/File/FileBackend.cs
index 28617c0b0..9896d4282 100644
--- a/Duplicati/Library/Backend/File/FileBackend.cs
+++ b/Duplicati/Library/Backend/File/FileBackend.cs
@@ -17,13 +17,15 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
+using Duplicati.Library.Common;
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
-using Duplicati.Library.Interface;
-using Duplicati.Library.Common.IO;
-using Duplicati.Library.Common;
-
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend
{
public class File : IBackend, IStreamingBackend, IQuotaEnabledBackend, IRenameEnabledBackend
@@ -186,7 +188,7 @@ namespace Duplicati.Library.Backend
#if DEBUG_RETRY
private static Random random = new Random();
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
using(System.IO.FileStream writestream = systemIO.FileOpenWrite(GetRemoteName(remotename)))
{
@@ -194,12 +196,15 @@ namespace Duplicati.Library.Backend
throw new Exception("Random upload failure");
Utility.Utility.CopyStream(stream, writestream);
}
+
+ return Task.FromResult(true);
}
#else
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
using(System.IO.FileStream writestream = systemIO.FileOpenWrite(GetRemoteName(remotename)))
Utility.Utility.CopyStream(stream, writestream, true, m_copybuffer);
+ return Task.FromResult(true);
}
#endif
@@ -210,7 +215,7 @@ namespace Duplicati.Library.Backend
Utility.Utility.CopyStream(readstream, stream, true, m_copybuffer);
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
string path = GetRemoteName(remotename);
if (m_moveFile)
@@ -222,6 +227,8 @@ namespace Duplicati.Library.Backend
}
else
systemIO.FileCopy(filename, path, true);
+
+ return Task.FromResult(true);
}
public void Get(string remotename, string filename)
diff --git a/Duplicati/Library/Backend/GoogleServices/GoogleCloudStorage.cs b/Duplicati/Library/Backend/GoogleServices/GoogleCloudStorage.cs
index 59b87a924..d8e5ac238 100644
--- a/Duplicati/Library/Backend/GoogleServices/GoogleCloudStorage.cs
+++ b/Duplicati/Library/Backend/GoogleServices/GoogleCloudStorage.cs
@@ -14,18 +14,18 @@
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+using Duplicati.Library.Backend.GoogleServices;
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
+using Duplicati.Library.Utility;
+using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
-using Newtonsoft.Json;
-
-using Duplicati.Library.Backend.GoogleServices;
-using Duplicati.Library.Interface;
-using Duplicati.Library.Utility;
-using Duplicati.Library.Common.IO;
-
namespace Duplicati.Library.Backend.GoogleCloudStorage
{
public class GoogleCloudStorage : IBackend, IStreamingBackend, IRenameEnabledBackend
@@ -147,10 +147,10 @@ namespace Duplicati.Library.Backend.GoogleCloudStorage
}
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
@@ -242,7 +242,7 @@ namespace Duplicati.Library.Backend.GoogleCloudStorage
#endregion
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
var item = new BucketResourceItem { name = m_prefix + remotename };
@@ -252,6 +252,8 @@ namespace Duplicati.Library.Backend.GoogleCloudStorage
if (res == null)
throw new Exception("Upload succeeded, but no data was returned");
+
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
diff --git a/Duplicati/Library/Backend/GoogleServices/GoogleDrive.cs b/Duplicati/Library/Backend/GoogleServices/GoogleDrive.cs
index 11bf54fb0..fd2e557a2 100644
--- a/Duplicati/Library/Backend/GoogleServices/GoogleDrive.cs
+++ b/Duplicati/Library/Backend/GoogleServices/GoogleDrive.cs
@@ -14,19 +14,19 @@
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+using Duplicati.Library.Backend.GoogleServices;
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
+using Duplicati.Library.Utility;
+using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
-using Newtonsoft.Json;
-
-using Duplicati.Library.Backend.GoogleServices;
-using Duplicati.Library.Interface;
-using Duplicati.Library.Utility;
-using Duplicati.Library.Common.IO;
-
namespace Duplicati.Library.Backend.GoogleDrive
{
public class GoogleDrive : IBackend, IStreamingBackend, IQuotaEnabledBackend, IRenameEnabledBackend
@@ -133,7 +133,7 @@ namespace Duplicati.Library.Backend.GoogleDrive
#region IStreamingBackend implementation
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
try
{
@@ -174,6 +174,8 @@ namespace Duplicati.Library.Backend.GoogleDrive
m_filecache.Clear();
throw;
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
@@ -249,10 +251,10 @@ namespace Duplicati.Library.Backend.GoogleDrive
}
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
diff --git a/Duplicati/Library/Backend/HubiC/HubiCBackend.cs b/Duplicati/Library/Backend/HubiC/HubiCBackend.cs
index da6942e63..f6ece03d6 100644
--- a/Duplicati/Library/Backend/HubiC/HubiCBackend.cs
+++ b/Duplicati/Library/Backend/HubiC/HubiCBackend.cs
@@ -14,11 +14,12 @@
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using Duplicati.Library.Interface;
-using Duplicati.Library;
using Duplicati.Library.Backend.OpenStack;
+using Duplicati.Library.Interface;
+using System;
using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
namespace Duplicati.Library.Backend.HubiC
{
@@ -105,9 +106,10 @@ namespace Duplicati.Library.Backend.HubiC
#region IStreamingBackend implementation
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
- m_openstack.Put(remotename, stream);
+ m_openstack.Put(remotename, stream, cancelToken);
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
@@ -124,9 +126,10 @@ namespace Duplicati.Library.Backend.HubiC
return m_openstack.List();
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
- m_openstack.Put(remotename, filename);
+ m_openstack.Put(remotename, filename, cancelToken);
+ return Task.FromResult(true);
}
public void Get(string remotename, string filename)
diff --git a/Duplicati/Library/Backend/Jottacloud/Jottacloud.cs b/Duplicati/Library/Backend/Jottacloud/Jottacloud.cs
index 472043acf..9603e613d 100644
--- a/Duplicati/Library/Backend/Jottacloud/Jottacloud.cs
+++ b/Duplicati/Library/Backend/Jottacloud/Jottacloud.cs
@@ -17,11 +17,13 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
using System;
using System.Collections.Generic;
-using Duplicati.Library.Interface;
-using Duplicati.Library.Common.IO;
-
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend
{
public class Jottacloud : IBackend, IStreamingBackend
@@ -220,10 +222,10 @@ namespace Duplicati.Library.Backend
}
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
@@ -334,7 +336,7 @@ namespace Duplicati.Library.Backend
Utility.Utility.CopyStream(s, stream, true, m_copybuffer);
}
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
// Some challenges with uploading to Jottacloud:
// - Jottacloud supports use of a custom header where we can tell the server the MD5 hash of the file
@@ -448,6 +450,8 @@ namespace Duplicati.Library.Backend
}
catch { }
}
+
+ return Task.FromResult(true);
}
#endregion
diff --git a/Duplicati/Library/Backend/Mega/MegaBackend.cs b/Duplicati/Library/Backend/Mega/MegaBackend.cs
index 2a5859922..52789316c 100644
--- a/Duplicati/Library/Backend/Mega/MegaBackend.cs
+++ b/Duplicati/Library/Backend/Mega/MegaBackend.cs
@@ -14,13 +14,15 @@
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-using System;
-using System.Linq;
-using System.Collections.Generic;
-using Duplicati.Library.Interface;
using CG.Web.MegaApiClient;
using Duplicati.Library.Common.IO;
-
+using Duplicati.Library.Interface;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend.Mega
{
public class MegaBackend: IBackend, IStreamingBackend
@@ -140,7 +142,7 @@ namespace Duplicati.Library.Backend.Mega
#region IStreamingBackend implementation
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
try
{
@@ -159,6 +161,8 @@ namespace Duplicati.Library.Backend.Mega
m_filecache = null;
throw;
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
@@ -182,10 +186,10 @@ namespace Duplicati.Library.Backend.Mega
select new FileEntry(item.Name, item.Size, item.ModificationDate ?? new DateTime(0), item.ModificationDate ?? new DateTime(0));
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
diff --git a/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs b/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs
index d3d80836a..ac37027c1 100644
--- a/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs
+++ b/Duplicati/Library/Backend/OneDrive/MicrosoftGraphBackend.cs
@@ -1,4 +1,9 @@
-using System;
+using Duplicati.Library.Backend.MicrosoftGraph;
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
+using Duplicati.Library.Utility;
+using Newtonsoft.Json;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -7,13 +12,7 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
-
-using Duplicati.Library.Backend.MicrosoftGraph;
-using Duplicati.Library.Interface;
-using Duplicati.Library.Common.IO;
-using Duplicati.Library.Utility;
-
-using Newtonsoft.Json;
+using System.Threading.Tasks;
namespace Duplicati.Library.Backend
{
@@ -327,15 +326,15 @@ namespace Duplicati.Library.Backend
}
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (FileStream fileStream = File.OpenRead(filename))
{
- this.Put(remotename, fileStream);
+ return Put(remotename, fileStream, cancelToken);
}
}
- public void Put(string remotename, Stream stream)
+ public Task Put(string remotename, Stream stream, CancellationToken cancelToken)
{
// PUT only supports up to 4 MB file uploads. There's a separate process for larger files.
if (stream.Length < PUT_MAX_SIZE)
@@ -429,6 +428,8 @@ namespace Duplicati.Library.Backend
}
}
}
+
+ return Task.FromResult(true);
}
public void Delete(string remotename)
diff --git a/Duplicati/Library/Backend/OpenStack/OpenStackStorage.cs b/Duplicati/Library/Backend/OpenStack/OpenStackStorage.cs
index 05e1a03d1..1e3840e32 100644
--- a/Duplicati/Library/Backend/OpenStack/OpenStackStorage.cs
+++ b/Duplicati/Library/Backend/OpenStack/OpenStackStorage.cs
@@ -26,7 +26,9 @@ using Duplicati.Library.Strings;
using System.Net;
using System.Text;
using Duplicati.Library.Common.IO;
-
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend.OpenStack
{
public class OpenStackStorage : IBackend, IStreamingBackend
@@ -483,11 +485,13 @@ namespace Duplicati.Library.Backend.OpenStack
}
#region IStreamingBackend implementation
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
var url = JoinUrls(SimpleStorageEndPoint, m_container, Library.Utility.Uri.UrlPathEncode(m_prefix + remotename));
using(m_helper.GetResponse(url, stream, "PUT"))
{ }
+
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
{
@@ -562,15 +566,17 @@ namespace Duplicati.Library.Backend.OpenStack
}
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
- using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ using (FileStream fs = File.OpenRead(filename))
+ Put(remotename, fs, cancelToken);
+
+ return Task.FromResult(true);
}
public void Get(string remotename, string filename)
{
- using (System.IO.FileStream fs = System.IO.File.Create(filename))
+ using (FileStream fs = File.Create(filename))
Get(remotename, fs);
}
public void Delete(string remotename)
diff --git a/Duplicati/Library/Backend/Rclone/Rclone.cs b/Duplicati/Library/Backend/Rclone/Rclone.cs
index a7c344caa..be5b0b0b7 100644
--- a/Duplicati/Library/Backend/Rclone/Rclone.cs
+++ b/Duplicati/Library/Backend/Rclone/Rclone.cs
@@ -17,18 +17,18 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Diagnostics;
+using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
-using System.Globalization;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
-using Duplicati.Library.Common.IO;
-
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend
{
public class Rclone : IBackend
@@ -225,7 +225,7 @@ namespace Duplicati.Library.Backend
}
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
try
{
@@ -235,6 +235,8 @@ namespace Duplicati.Library.Backend
{
throw new FileMissingException(ex);
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, string filename)
diff --git a/Duplicati/Library/Backend/S3/S3Backend.cs b/Duplicati/Library/Backend/S3/S3Backend.cs
index 988268d63..0692b01cd 100644
--- a/Duplicati/Library/Backend/S3/S3Backend.cs
+++ b/Duplicati/Library/Backend/S3/S3Backend.cs
@@ -17,13 +17,15 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
-using Duplicati.Library.Common.IO;
+using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
+using System.Threading;
+using System.Threading.Tasks;
namespace Duplicati.Library.Backend
{
@@ -339,13 +341,13 @@ namespace Duplicati.Library.Backend
}
}
- public void Put(string remotename, string localname)
+ public Task Put(string remotename, string localname, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.Open(localname, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
- public void Put(string remotename, System.IO.Stream input)
+ public Task Put(string remotename, System.IO.Stream input, CancellationToken cancelToken)
{
try
{
@@ -360,6 +362,8 @@ namespace Duplicati.Library.Backend
throw;
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, string localname)
diff --git a/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs b/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs
index 5f057042d..e743407cb 100644
--- a/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs
+++ b/Duplicati/Library/Backend/SSHv2/SSHv2Backend.cs
@@ -17,15 +17,16 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Duplicati.Library.Interface;
using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
using Renci.SshNet;
using Renci.SshNet.Common;
+using System;
+using System.Collections.Generic;
using System.Globalization;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
namespace Duplicati.Library.Backend
{
@@ -147,10 +148,10 @@ namespace Duplicati.Library.Backend
get { return "ssh"; }
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
@@ -225,11 +226,12 @@ namespace Duplicati.Library.Backend
#region IStreamingBackend Implementation
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
CreateConnection();
ChangeDirectory(m_path);
m_con.UploadFile(stream, remotename);
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
diff --git a/Duplicati/Library/Backend/SharePoint/SharePointBackend.cs b/Duplicati/Library/Backend/SharePoint/SharePointBackend.cs
index 5fcfc023a..897be220f 100644
--- a/Duplicati/Library/Backend/SharePoint/SharePointBackend.cs
+++ b/Duplicati/Library/Backend/SharePoint/SharePointBackend.cs
@@ -18,19 +18,19 @@
//
#endregion
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
+using Duplicati.Library.Utility;
+using Microsoft.SharePoint.Client; // Plain 'using' for extension methods
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
-using Duplicati.Library.Utility;
-
-using Duplicati.Library.Interface;
-
+using System.Threading;
+using System.Threading.Tasks;
using SP = Microsoft.SharePoint.Client;
-using Microsoft.SharePoint.Client; // Plain 'using' for extension methods
-using Duplicati.Library.Common.IO;
-
+
namespace Duplicati.Library.Backend
{
@@ -523,14 +523,14 @@ namespace Duplicati.Library.Backend
Utility.Utility.CopyStream(s, stream, true, copybuffer);
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
- using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ using (FileStream fs = System.IO.File.OpenRead(filename))
+ return Put(remotename, fs, cancelToken);
}
- public void Put(string remotename, System.IO.Stream stream) { doPut(remotename, stream, false); }
- private void doPut(string remotename, System.IO.Stream stream, bool useNewContext)
+ public Task Put(string remotename, Stream stream, CancellationToken cancelToken) { return doPut(remotename, stream, false, cancelToken); }
+ private Task doPut(string remotename, Stream stream, bool useNewContext, CancellationToken cancelToken)
{
string fileurl = m_serverRelPath + System.Web.HttpUtility.UrlPathEncode(remotename);
SP.ClientContext ctx = getSpClientContext(useNewContext);
@@ -549,13 +549,14 @@ namespace Duplicati.Library.Backend
catch (ServerException) { throw; /* rethrow if Server answered */ }
catch (Interface.FileMissingException) { throw; }
catch (Interface.FolderMissingException) { throw; }
- catch { if (!useNewContext) /* retry */ { doPut(remotename, stream, true); return; } else throw; }
+ catch { if (!useNewContext) /* retry */ { return doPut(remotename, stream, true, cancelToken); } else throw; }
if (m_useBinaryDirectMode)
{
SP.File.SaveBinaryDirect(ctx, fileurl, stream, true);
}
+ return Task.FromResult(true);
}
/// <summary>
diff --git a/Duplicati/Library/Backend/Sia/Sia.cs b/Duplicati/Library/Backend/Sia/Sia.cs
index 2908a2898..1ff1380fd 100644
--- a/Duplicati/Library/Backend/Sia/Sia.cs
+++ b/Duplicati/Library/Backend/Sia/Sia.cs
@@ -1,13 +1,13 @@
-using System;
-using System.Linq;
-using System.Collections.Generic;
-using System.Net;
-
+using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using Duplicati.Library.Utility;
using Newtonsoft.Json;
-using Duplicati.Library.Common.IO;
-
+using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend.Sia
{
public class Sia : IBackend
@@ -306,7 +306,7 @@ namespace Duplicati.Library.Backend.Sia
}
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
string endpoint ="";
string siafile = m_targetpath + "/" + remotename;
@@ -314,31 +314,33 @@ namespace Duplicati.Library.Backend.Sia
try {
endpoint = string.Format("/renter/upload/{0}/{1}?source={2}",
m_targetpath,
- Library.Utility.Uri.UrlEncode(remotename).Replace("+", "%20"),
- Library.Utility.Uri.UrlEncode(filename).Replace("+", "%20")
+ Utility.Uri.UrlEncode(remotename).Replace("+", "%20"),
+ Utility.Uri.UrlEncode(filename).Replace("+", "%20")
);
- System.Net.HttpWebRequest req = CreateRequest(endpoint);
- req.Method = System.Net.WebRequestMethods.Http.Post;
+ HttpWebRequest req = CreateRequest(endpoint);
+ req.Method = WebRequestMethods.Http.Post;
- Utility.AsyncHttpRequest areq = new Utility.AsyncHttpRequest(req);
+ AsyncHttpRequest areq = new AsyncHttpRequest(req);
- using (System.Net.HttpWebResponse resp = (System.Net.HttpWebResponse)areq.GetResponse())
+ using (HttpWebResponse resp = (HttpWebResponse)areq.GetResponse())
{
int code = (int)resp.StatusCode;
if (code < 200 || code >= 300)
- throw new System.Net.WebException(resp.StatusDescription, null, System.Net.WebExceptionStatus.ProtocolError, resp);
+ throw new WebException(resp.StatusDescription, null, WebExceptionStatus.ProtocolError, resp);
while (! IsUploadComplete( siafile ))
{
- System.Threading.Thread.Sleep(5000);
+ Thread.Sleep(5000);
}
}
}
- catch (System.Net.WebException wex)
+ catch (WebException wex)
{
throw new Exception(getResponseBodyOnError(endpoint, wex));
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, string localname)
diff --git a/Duplicati/Library/Backend/TahoeLAFS/TahoeBackend.cs b/Duplicati/Library/Backend/TahoeLAFS/TahoeBackend.cs
index f253a2686..80cfe9ad5 100644
--- a/Duplicati/Library/Backend/TahoeLAFS/TahoeBackend.cs
+++ b/Duplicati/Library/Backend/TahoeLAFS/TahoeBackend.cs
@@ -17,15 +17,15 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
-using System;
-using System.Collections.Generic;
-using System.Text;
+using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
-using System.Linq;
-using Duplicati.Library.Common.IO;
-
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend
{
public class TahoeBackend : IBackend, IStreamingBackend
@@ -208,10 +208,10 @@ namespace Duplicati.Library.Backend
}
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
@@ -271,7 +271,7 @@ namespace Duplicati.Library.Backend
#region IStreamingBackend Members
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
try
{
@@ -302,6 +302,8 @@ namespace Duplicati.Library.Backend
throw;
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
diff --git a/Duplicati/Library/Backend/WEBDAV/WEBDAV.cs b/Duplicati/Library/Backend/WEBDAV/WEBDAV.cs
index 8d175cc4b..58c491f5f 100644
--- a/Duplicati/Library/Backend/WEBDAV/WEBDAV.cs
+++ b/Duplicati/Library/Backend/WEBDAV/WEBDAV.cs
@@ -17,12 +17,13 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
+using Duplicati.Library.Common.IO;
+using Duplicati.Library.Interface;
using System;
using System.Collections.Generic;
-using System.Text;
-using Duplicati.Library.Interface;
-using Duplicati.Library.Common.IO;
-
+using System.Threading;
+using System.Threading.Tasks;
+
namespace Duplicati.Library.Backend
{
public class WEBDAV : IBackend, IStreamingBackend
@@ -254,10 +255,10 @@ namespace Duplicati.Library.Backend
return files;
}
- public void Put(string remotename, string filename)
+ public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
- Put(remotename, fs);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
@@ -375,7 +376,7 @@ namespace Duplicati.Library.Backend
#region IStreamingBackend Members
- public void Put(string remotename, System.IO.Stream stream)
+ public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
try
{
@@ -406,6 +407,8 @@ namespace Duplicati.Library.Backend
throw;
}
+
+ return Task.FromResult(true);
}
public void Get(string remotename, System.IO.Stream stream)
diff --git a/Duplicati/Library/Interface/IBackend.cs b/Duplicati/Library/Interface/IBackend.cs
index ba9571e6f..82e614b07 100644
--- a/Duplicati/Library/Interface/IBackend.cs
+++ b/Duplicati/Library/Interface/IBackend.cs
@@ -19,7 +19,8 @@
#endregion
using System;
using System.Collections.Generic;
-using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
namespace Duplicati.Library.Interface
{
@@ -56,7 +57,8 @@ namespace Duplicati.Library.Interface
/// </summary>
/// <param name="remotename">The remote filename, relative to the URL</param>
/// <param name="filename">The local filename</param>
- void Put(string remotename, string filename);
+ /// <param name="cancelToken">Token to cancel the operation.</param>
+ Task Put(string remotename, string filename, CancellationToken cancelToken);
/// <summary>
/// Downloads a file with the remote data
diff --git a/Duplicati/Library/Interface/IStreamingBackend.cs b/Duplicati/Library/Interface/IStreamingBackend.cs
index 740d4a670..33b8baff2 100644
--- a/Duplicati/Library/Interface/IStreamingBackend.cs
+++ b/Duplicati/Library/Interface/IStreamingBackend.cs
@@ -17,9 +17,8 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
-using System;
-using System.Collections.Generic;
-using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
namespace Duplicati.Library.Interface
{
@@ -35,7 +34,8 @@ namespace Duplicati.Library.Interface
/// </summary>
/// <param name="remotename">The remote filename, relative to the URL</param>
/// <param name="stream">The stream to read from</param>
- void Put(string remotename, System.IO.Stream stream);
+ /// <param name="cancelToken">Token to cancel the operation.</param>
+ Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken);
/// <summary>
/// Downloads a file with the remote data
diff --git a/Duplicati/Library/Main/BackendManager.cs b/Duplicati/Library/Main/BackendManager.cs
index 26e9443dc..a226445d7 100644
--- a/Duplicati/Library/Main/BackendManager.cs
+++ b/Duplicati/Library/Main/BackendManager.cs
@@ -7,6 +7,7 @@ using Duplicati.Library.Main.Database;
using Duplicati.Library.Main.Volumes;
using Newtonsoft.Json;
using Duplicati.Library.Localization.Short;
+using System.Threading;
namespace Duplicati.Library.Main
{
@@ -734,10 +735,10 @@ namespace Duplicati.Library.Main
using (var fs = System.IO.File.OpenRead(item.LocalFilename))
using (var ts = new ThrottledStream(fs, m_options.MaxUploadPrSecond, m_options.MaxDownloadPrSecond))
using (var pgs = new Library.Utility.ProgressReportingStream(ts, pg => HandleProgress(ts, pg)))
- ((Library.Interface.IStreamingBackend)m_backend).Put(item.RemoteFilename, pgs);
+ ((Library.Interface.IStreamingBackend)m_backend).Put(item.RemoteFilename, pgs, CancellationToken.None).Wait();
}
else
- m_backend.Put(item.RemoteFilename, item.LocalFilename);
+ m_backend.Put(item.RemoteFilename, item.LocalFilename, CancellationToken.None).Wait();
var duration = DateTime.Now - begin;
Logging.Log.WriteProfilingMessage(LOGTAG, "UploadSpeed", "Uploaded {0} in {1}, {2}/s", Library.Utility.Utility.FormatSizeString(item.Size), duration, Library.Utility.Utility.FormatSizeString((long)(item.Size / duration.TotalSeconds)));
diff --git a/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs b/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs
index 24e40bf7e..ef4913efb 100644
--- a/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs
+++ b/Duplicati/Library/Main/Operation/Backup/BackendUploader.cs
@@ -24,6 +24,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
using static Duplicati.Library.Main.Operation.Common.BackendHandler;
@@ -88,6 +89,7 @@ namespace Duplicati.Library.Main.Operation.Backup
private static readonly string LOGTAG = Logging.Log.LogTagFromType<BackendUploader>();
private Func<IBackend> m_backendFactory;
+ private CancellationTokenSource m_cancelTokenSource;
private Options m_options;
private ITaskReader m_taskreader;
private StatsCollector m_stats;
@@ -119,6 +121,7 @@ namespace Duplicati.Library.Main.Operation.Backup
var max_pending = m_options.AsynchronousUploadLimit == 0 ? long.MaxValue : m_options.AsynchronousUploadLimit;
var lastSize = -1L;
var uploadsInProgress = 0;
+ m_cancelTokenSource = new CancellationTokenSource();
while (!await self.Input.IsRetiredAsync && await m_taskreader.ProgressAsync)
{
@@ -139,21 +142,21 @@ namespace Duplicati.Library.Main.Operation.Backup
if (req is VolumeUploadRequest volumeUpload)
{
if (volumeUpload.IndexVolume == null)
- worker.Task = Task.Run(() => UploadFileAsync(volumeUpload.BlockEntry, worker));
+ worker.Task = Task.Run(() => UploadFileAsync(volumeUpload.BlockEntry, worker, m_cancelTokenSource.Token));
else
- worker.Task = Task.Run(() => UploadBlockAndIndexAsync(volumeUpload, worker));
+ worker.Task = Task.Run(() => UploadBlockAndIndexAsync(volumeUpload, worker, m_cancelTokenSource.Token));
lastSize = volumeUpload.BlockVolume.SourceSize;
uploadsInProgress++;
}
else if (req is FilesetUploadRequest filesetUpload)
{
- worker.Task = Task.Run(() => UploadVolumeWriter(filesetUpload.Fileset, worker));
+ worker.Task = Task.Run(() => UploadVolumeWriter(filesetUpload.Fileset, worker, m_cancelTokenSource.Token));
uploadsInProgress++;
}
else if (req is IndexVolumeUploadRequest indexUpload)
{
- worker.Task = Task.Run(() => UploadVolumeWriter(indexUpload.IndexVolume, worker));
+ worker.Task = Task.Run(() => UploadVolumeWriter(indexUpload.IndexVolume, worker, m_cancelTokenSource.Token));
uploadsInProgress++;
}
else if (req is FlushRequest flush)
@@ -198,30 +201,30 @@ namespace Duplicati.Library.Main.Operation.Backup
});
}
- private async Task UploadBlockAndIndexAsync(VolumeUploadRequest upload, Worker worker)
+ private async Task UploadBlockAndIndexAsync(VolumeUploadRequest upload, Worker worker, CancellationToken cancelToken)
{
- await UploadFileAsync(upload.BlockEntry, worker).ConfigureAwait(false);
- await UploadFileAsync(upload.IndexEntry, worker).ConfigureAwait(false);
+ await UploadFileAsync(upload.BlockEntry, worker, cancelToken).ConfigureAwait(false);
+ await UploadFileAsync(upload.IndexEntry, worker, cancelToken).ConfigureAwait(false);
await m_database.AddIndexBlockLinkAsync(upload.IndexVolume.VolumeID, upload.BlockVolume.VolumeID).ConfigureAwait(false);
}
- private async Task UploadVolumeWriter(VolumeWriterBase volumeWriter, Worker worker)
+ private async Task UploadVolumeWriter(VolumeWriterBase volumeWriter, Worker worker, CancellationToken cancelToken)
{
var fileEntry = new FileEntryItem(BackendActionType.Put, volumeWriter.RemoteFilename);
fileEntry.SetLocalfilename(volumeWriter.LocalFilename);
fileEntry.Encrypt(m_options);
fileEntry.UpdateHashAndSize(m_options);
- await UploadFileAsync(fileEntry, worker).ConfigureAwait(false);
+ await UploadFileAsync(fileEntry, worker, cancelToken).ConfigureAwait(false);
}
- private async Task UploadFileAsync(FileEntryItem item, Worker worker)
+ private async Task UploadFileAsync(FileEntryItem item, Worker worker, CancellationToken cancelToken)
{
await DoWithRetry(item, worker, async () =>
{
if (item.IsRetry)
await RenameFileAfterErrorAsync(item).ConfigureAwait(false);
- await DoPut(item, worker.Backend).ConfigureAwait(false);
+ await DoPut(item, worker.Backend, cancelToken).ConfigureAwait(false);
}).ConfigureAwait(false);
}
@@ -318,7 +321,7 @@ namespace Duplicati.Library.Main.Operation.Backup
item.RemoteFilename = newname;
}
- private async Task DoPut(FileEntryItem item, IBackend backend)
+ private async Task DoPut(FileEntryItem item, IBackend backend, CancellationToken cancelToken)
{
if (item.TrackedInDb)
await m_database.UpdateRemoteVolumeAsync(item.RemoteFilename, RemoteVolumeState.Uploading, item.Size, item.Hash);
@@ -340,10 +343,10 @@ namespace Duplicati.Library.Main.Operation.Backup
using (var fs = File.OpenRead(item.LocalFilename))
using (var ts = new ThrottledStream(fs, m_options.MaxUploadPrSecond, m_options.MaxDownloadPrSecond))
using (var pgs = new ProgressReportingStream(ts, pg => HandleProgress(ts, pg)))
- streamingBackend.Put(item.RemoteFilename, pgs);
+ await streamingBackend.Put(item.RemoteFilename, pgs, cancelToken).ConfigureAwait(false);
}
else
- backend.Put(item.RemoteFilename, item.LocalFilename);
+ await backend.Put(item.RemoteFilename, item.LocalFilename, cancelToken).ConfigureAwait(false);
var duration = DateTime.Now - begin;
Logging.Log.WriteProfilingMessage(LOGTAG, "UploadSpeed", "Uploaded {0} in {1}, {2}/s", Library.Utility.Utility.FormatSizeString(item.Size), duration, Library.Utility.Utility.FormatSizeString((long)(item.Size / duration.TotalSeconds)));