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:
authorTyler Gill <tyler.gill@byu.net>2017-09-26 08:17:45 +0300
committerTyler Gill <tyler.gill@byu.net>2017-09-26 08:17:45 +0300
commit38883285eee5598e37d56e6ddc417fad7d872ed3 (patch)
treed542798f8594aca02d954128f0fe63f32f28b512 /Duplicati/Library/Interface
parent6c921ab3ec878a99262150b80b7f29713700c11e (diff)
Change IBackend.List() to return IEnumerable instead of List
By changing to IEnumerable, it is possible to iterate only a portion of the list, which is useful when not all entries are needed (e.g., when testing a connection). All existing backends have been updated, and any which were able to be changed to yield return results in a straightforward way now do. Many backends had a try/catch in the List() method. Due to the fact that yield returns can't be placed within a try/catch block, these have been refactored to either scope the try/catch to the parts that (should) be the only places throwing exceptions, so that exceptions are still caught and handled. Note that lazy evaluation may cause some changes in behavior - exceptions that were previously thrown at the point of invokation of List() may now be thrown while it is being enumerated. I believe this will not be problematic though, as the only well-known exception seems to be FolderMissingException, which should be thrown by Test(), but TestList() attempts to enumerate the list to force this exception. Any places that require the legacy behavior can get it by simply converting the lazy enumerable to a List()
Diffstat (limited to 'Duplicati/Library/Interface')
-rw-r--r--Duplicati/Library/Interface/BackendExtensions.cs28
-rw-r--r--Duplicati/Library/Interface/Duplicati.Library.Interface.csproj1
-rw-r--r--Duplicati/Library/Interface/IBackend.cs4
3 files changed, 31 insertions, 2 deletions
diff --git a/Duplicati/Library/Interface/BackendExtensions.cs b/Duplicati/Library/Interface/BackendExtensions.cs
new file mode 100644
index 000000000..486632d76
--- /dev/null
+++ b/Duplicati/Library/Interface/BackendExtensions.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Duplicati.Library.Interface
+{
+ /// <summary>
+ /// Contains extension methods for the IBackend interfaces
+ /// </summary>
+ public static class BackendExtensions
+ {
+ /// <summary>
+ /// Tests a backend by invoking the List() method.
+ /// As long as the iteration can either complete or find at least one file without throwing, the test is successful
+ /// </summary>
+ /// <param name="backend">Backend to test</param>
+ public static void TestList(this IBackend backend)
+ {
+ // If we can iterate successfully, even if it's empty, then the backend test is successful
+ foreach (IFileEntry file in backend.List())
+ {
+ break;
+ }
+ }
+ }
+}
diff --git a/Duplicati/Library/Interface/Duplicati.Library.Interface.csproj b/Duplicati/Library/Interface/Duplicati.Library.Interface.csproj
index 5a2b82a5c..59d5026e0 100644
--- a/Duplicati/Library/Interface/Duplicati.Library.Interface.csproj
+++ b/Duplicati/Library/Interface/Duplicati.Library.Interface.csproj
@@ -42,6 +42,7 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="BackendExtensions.cs" />
<Compile Include="CommandLineArgument.cs" />
<Compile Include="CommonStrings.cs" />
<Compile Include="CustomExceptions.cs" />
diff --git a/Duplicati/Library/Interface/IBackend.cs b/Duplicati/Library/Interface/IBackend.cs
index a8b5532b9..8281a9372 100644
--- a/Duplicati/Library/Interface/IBackend.cs
+++ b/Duplicati/Library/Interface/IBackend.cs
@@ -46,10 +46,10 @@ namespace Duplicati.Library.Interface
string ProtocolKey { get; }
/// <summary>
- /// Returns a list of files found on the remote location
+ /// Enumerates a list of files found on the remote location
/// </summary>
/// <returns>The list of files</returns>
- List<IFileEntry> List();
+ IEnumerable<IFileEntry> List();
/// <summary>
/// Puts the content of the file to the url passed