Fix bug in PutAsync implementations.
Without await, the using statement can dispose the Stream before the call to PutAsync completes, resulting in an ObjectDisposedException. This fixes #4556.
This commit is contained in:
@@ -30,8 +30,8 @@ using System.Security.Authentication;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CoreUtility = Duplicati.Library.Utility.Utility;
|
||||
using Uri = System.Uri;
|
||||
|
||||
using Uri = System.Uri;
|
||||
|
||||
namespace Duplicati.Library.Backend.AlternativeFTP
|
||||
{
|
||||
// ReSharper disable once RedundantExtendsListEntry
|
||||
@@ -370,11 +370,11 @@ namespace Duplicati.Library.Backend.AlternativeFTP
|
||||
}
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string localname, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string localname, CancellationToken cancelToken)
|
||||
{
|
||||
using (FileStream fs = File.Open(localname, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,12 +101,12 @@ namespace Duplicati.Library.Backend.AzureBlob
|
||||
return _azureBlob.ListContainerEntries();
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string localname, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string localname, CancellationToken cancelToken)
|
||||
{
|
||||
using (var fs = File.Open(localname,
|
||||
FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ namespace Duplicati.Library.Backend.Backblaze
|
||||
public class B2 : IBackend, IStreamingBackend
|
||||
{
|
||||
private const string B2_ID_OPTION = "b2-accountid";
|
||||
private const string B2_KEY_OPTION = "b2-applicationkey";
|
||||
private const string B2_PAGESIZE_OPTION = "b2-page-size";
|
||||
private const string B2_KEY_OPTION = "b2-applicationkey";
|
||||
private const string B2_PAGESIZE_OPTION = "b2-page-size";
|
||||
private const string B2_DOWNLOAD_URL_OPTION = "b2-download-url";
|
||||
|
||||
|
||||
private const string B2_CREATE_BUCKET_TYPE_OPTION = "b2-create-bucket-type";
|
||||
private const string DEFAULT_BUCKET_TYPE = "allPrivate";
|
||||
|
||||
@@ -95,9 +95,9 @@ namespace Duplicati.Library.Backend.Backblaze
|
||||
if (string.IsNullOrEmpty(accountKey))
|
||||
throw new UserInformationException(Strings.B2.NoB2KeyError, "B2MissingKey");
|
||||
|
||||
m_helper = new B2AuthHelper(accountId, accountKey);
|
||||
|
||||
m_pagesize = DEFAULT_PAGE_SIZE;
|
||||
m_helper = new B2AuthHelper(accountId, accountKey);
|
||||
|
||||
m_pagesize = DEFAULT_PAGE_SIZE;
|
||||
if (options.ContainsKey(B2_PAGESIZE_OPTION))
|
||||
{
|
||||
int.TryParse(options[B2_PAGESIZE_OPTION], out m_pagesize);
|
||||
@@ -182,8 +182,8 @@ namespace Duplicati.Library.Backend.Backblaze
|
||||
new CommandLineArgument(B2_KEY_OPTION, CommandLineArgument.ArgumentType.Password, Strings.B2.B2applicationkeyDescriptionShort, Strings.B2.B2applicationkeyDescriptionLong, null, new string[] {"auth-username"}, null),
|
||||
new CommandLineArgument("auth-password", CommandLineArgument.ArgumentType.Password, Strings.B2.AuthPasswordDescriptionShort, Strings.B2.AuthPasswordDescriptionLong),
|
||||
new CommandLineArgument("auth-username", CommandLineArgument.ArgumentType.String, Strings.B2.AuthUsernameDescriptionShort, Strings.B2.AuthUsernameDescriptionLong),
|
||||
new CommandLineArgument(B2_CREATE_BUCKET_TYPE_OPTION, CommandLineArgument.ArgumentType.String, Strings.B2.B2createbuckettypeDescriptionShort, Strings.B2.B2createbuckettypeDescriptionLong, DEFAULT_BUCKET_TYPE),
|
||||
new CommandLineArgument(B2_PAGESIZE_OPTION, CommandLineArgument.ArgumentType.Integer, Strings.B2.B2pagesizeDescriptionShort, Strings.B2.B2pagesizeDescriptionLong, DEFAULT_PAGE_SIZE.ToString()),
|
||||
new CommandLineArgument(B2_CREATE_BUCKET_TYPE_OPTION, CommandLineArgument.ArgumentType.String, Strings.B2.B2createbuckettypeDescriptionShort, Strings.B2.B2createbuckettypeDescriptionLong, DEFAULT_BUCKET_TYPE),
|
||||
new CommandLineArgument(B2_PAGESIZE_OPTION, CommandLineArgument.ArgumentType.Integer, Strings.B2.B2pagesizeDescriptionShort, Strings.B2.B2pagesizeDescriptionLong, DEFAULT_PAGE_SIZE.ToString()),
|
||||
new CommandLineArgument(B2_DOWNLOAD_URL_OPTION, CommandLineArgument.ArgumentType.String, Strings.B2.B2downloadurlDescriptionShort, Strings.B2.B2downloadurlDescriptionLong),
|
||||
});
|
||||
|
||||
@@ -362,10 +362,10 @@ namespace Duplicati.Library.Backend.Backblaze
|
||||
).ToList();
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -260,10 +260,10 @@ namespace Duplicati.Library.Backend.Box
|
||||
select (IFileEntry)new FileEntry(n.Name, n.Size, n.ModifiedAt, n.ModifiedAt) { IsFolder = n.Type == "folder" };
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -194,10 +194,10 @@ namespace Duplicati.Library.Backend
|
||||
} while (repeat);
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -107,10 +107,10 @@ namespace Duplicati.Library.Backend
|
||||
}
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using(FileStream fs = File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -296,10 +296,10 @@ namespace Duplicati.Library.Backend
|
||||
}
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string localname, CancellationToken cancelToken)
|
||||
public async Task PutAsync(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))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, System.IO.Stream output)
|
||||
|
||||
@@ -139,10 +139,10 @@ namespace Duplicati.Library.Backend.GoogleCloudStorage
|
||||
}
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -253,10 +253,10 @@ namespace Duplicati.Library.Backend.GoogleDrive
|
||||
}
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -304,10 +304,10 @@ namespace Duplicati.Library.Backend
|
||||
return ToFileEntry(xFile);
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -186,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 Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -565,10 +565,10 @@ namespace Duplicati.Library.Backend.OpenStack
|
||||
}
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (FileStream fs = File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -341,10 +341,10 @@ namespace Duplicati.Library.Backend
|
||||
}
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string localname, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string localname, CancellationToken cancelToken)
|
||||
{
|
||||
using (FileStream fs = File.Open(localname, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public async Task PutAsync(string remotename, Stream input, CancellationToken cancelToken)
|
||||
|
||||
@@ -167,11 +167,11 @@ namespace Duplicati.Library.Backend
|
||||
|
||||
public string ProtocolKey => "ssh";
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(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))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -518,10 +518,10 @@ namespace Duplicati.Library.Backend
|
||||
Utility.Utility.CopyStream(s, stream, true, copybuffer);
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (FileStream fs = System.IO.File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, Stream stream, CancellationToken cancelToken) { return doPut(remotename, stream, false, cancelToken); }
|
||||
|
||||
@@ -209,10 +209,10 @@ namespace Duplicati.Library.Backend
|
||||
}
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -196,10 +196,10 @@ namespace Duplicati.Library.Backend.TencentCOS
|
||||
}
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
@@ -256,10 +256,10 @@ namespace Duplicati.Library.Backend
|
||||
return files;
|
||||
}
|
||||
|
||||
public Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
public async Task PutAsync(string remotename, string filename, CancellationToken cancelToken)
|
||||
{
|
||||
using (System.IO.FileStream fs = System.IO.File.OpenRead(filename))
|
||||
return PutAsync(remotename, fs, cancelToken);
|
||||
await PutAsync(remotename, fs, cancelToken);
|
||||
}
|
||||
|
||||
public void Get(string remotename, string filename)
|
||||
|
||||
Reference in New Issue
Block a user