Merge pull request #6462 from duplicati/feature/fix-warnings-nullable

Fixed compile warnings
This commit is contained in:
Kenneth Skovhede
2025-08-07 10:21:42 +02:00
committed by GitHub
17 changed files with 662 additions and 660 deletions
@@ -56,7 +56,7 @@ namespace Duplicati.Library.Backend.AliyunOSS
{
_timeouts = TimeoutOptionsHelper.Parse(options);
var uri = new Utility.Uri(url?.Trim());
var uri = new Utility.Uri(url?.Trim() ?? "");
var prefix = uri.HostAndPath?.TrimPath();
var auth = AuthOptionsHelper.ParseWithAlias(options, uri, OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET)
@@ -88,7 +88,7 @@ namespace Duplicati.Library.Backend.AzureBlob
var uri = new Utility.Uri(url);
uri.RequireHost();
var containerName = uri.Host.ToLowerInvariant();
var containerName = (uri.Host ?? "").ToLowerInvariant();
var auth = AuthOptionsHelper.ParseWithAlias(options, uri, AZURE_ACCOUNT_NAME_OPTION, AZURE_ACCESS_KEY_OPTION);
var timeouts = TimeoutOptionsHelper.Parse(options);
File diff suppressed because it is too large Load Diff
@@ -62,7 +62,7 @@ namespace Duplicati.Library.Backend.GoogleCloudStorage
{
var uri = new Utility.Uri(url);
m_bucket = uri.Host;
m_bucket = uri.Host ?? "";
m_prefix = Util.AppendDirSeparator("/" + uri.Path, "/");
// For GCS we do not use a leading slash
@@ -58,7 +58,7 @@ namespace Duplicati.Library.Backend
client.Timeout = Timeout.InfiniteTimeSpan;
return client;
});
/// <summary>
/// The timeout options
/// </summary>
@@ -86,7 +86,7 @@ namespace Duplicati.Library.Backend
public Idrivee2Backend(string url, Dictionary<string, string?> options)
{
var uri = new Utility.Uri(url);
_bucket = uri.Host;
_bucket = uri.Host ?? "";
_prefix = uri.Path;
_prefix = _prefix.Trim();
if (_prefix.Length != 0)
@@ -110,7 +110,7 @@ public class OpenStackStorage : IStreamingBackend
{
var uri = new Uri(url);
m_container = uri.Host;
m_container = uri.Host ?? "";
m_prefix = Util.AppendDirSeparator("/" + uri.Path, "/");
_timeouts = TimeoutOptionsHelper.Parse(options);
+1 -1
View File
@@ -74,7 +74,7 @@ namespace Duplicati.Library.Backend
if (string.IsNullOrWhiteSpace(local_repo))
local_repo = "local";
if (string.IsNullOrWhiteSpace(remote_repo))
remote_repo = uri.Host;
remote_repo = uri.Host ?? "";
if (string.IsNullOrWhiteSpace(remote_path))
remote_path = uri.Path;
if (string.IsNullOrWhiteSpace(rclone_executable))
+1 -1
View File
@@ -209,7 +209,7 @@ namespace Duplicati.Library.Backend
var uri = new Utility.Uri(url);
uri.RequireHost();
m_bucket = uri.Host;
m_bucket = uri.Host ?? "";
m_prefix = uri.Path;
var timeout = TimeoutOptionsHelper.Parse(options);
+2 -2
View File
@@ -134,7 +134,7 @@ public class SMBBackend : IStreamingBackend, IFolderEnabledBackend
var uri = new Utility.Uri(url);
uri.RequireHost();
_DnsName = uri.Host;
_DnsName = uri.Host ?? "";
var input = uri.Path.TrimEnd('/');
var slashIndex = input.IndexOf('/'); // Find first slash to separate server and share if present.
@@ -165,7 +165,7 @@ public class SMBBackend : IStreamingBackend, IFolderEnabledBackend
_timeouts = TimeoutOptionsHelper.Parse(options);
_connectionParameters = new SMBConnectionParameters(
uri.Host,
_DnsName,
transportType,
slashIndex >= 0 ? input[..slashIndex] : input,
slashIndex >= 0 ? input[(slashIndex + 1)..] : "",
@@ -112,7 +112,7 @@ namespace Duplicati.Library.Backend
m_path = "/" + m_path;
}
m_server = uri.Host;
m_server = uri.Host ?? "";
if (uri.Port > 0)
m_port = uri.Port;
@@ -655,6 +655,8 @@ namespace Duplicati.Library.Backend
var ctx = await GetSpClientContextAsync(useNewContext, cancelToken).ConfigureAwait(false);
try
{
if (string.IsNullOrWhiteSpace(m_spWebUrl))
throw new HttpRequestException(Strings.SharePoint.NoSharePointWebFoundError(m_orgUrl.ToString()));
var pathLengthToWeb = new Utility.Uri(m_spWebUrl).Path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Length;
var folderNames = m_serverRelPath.Substring(0, m_serverRelPath.Length - 1).Split('/');
@@ -123,7 +123,7 @@ namespace Duplicati.Library.Backend.TencentCOS
public COS(string url, Dictionary<string, string?> options)
{
var uri = new Utility.Uri(url?.Trim());
var uri = new Utility.Uri(url?.Trim() ?? "");
var prefix = uri.HostAndPath?.Trim()?.Trim('/')?.Trim('\\');
var auth = AuthOptionsHelper.ParseWithAlias(options, uri, COS_SECRET_ID, COS_SECRET_KEY)
.RequireCredentials();
+1 -1
View File
@@ -142,7 +142,7 @@ namespace Duplicati.Library.Backend
{
var u = new Utility.Uri(url);
u.RequireHost();
m_dnsName = u.Host;
m_dnsName = u.Host ?? "";
var auth = AuthOptionsHelper.Parse(options, u);
if (auth.HasUsername)
{
@@ -128,22 +128,22 @@ public class pCloudBackend : IStreamingBackend
{
var uri = new Utility.Uri(url);
uri.RequireHost();
_DnsName = uri.Host;
_DnsName = uri.Host ?? "";
_Token = AuthIdOptionsHelper.Parse(options)
.RequireCredentials(TOKEN_URL)
.AuthId!;
if (!PCLOUD_SERVERS.ContainsValue(uri.Host))
if (!PCLOUD_SERVERS.ContainsValue(_DnsName))
throw new UserInformationException(Strings.pCloudBackend.InvalidServerSpecified,
"InvalidpCloudServerSpecified");
if (string.IsNullOrWhiteSpace(uri.Host))
if (string.IsNullOrWhiteSpace(_DnsName))
throw new UserInformationException(Strings.pCloudBackend.NoServerSpecified, "NopCloudServerSpecified");
// Ensure that the path is in the correct format, without starting or tailing slashes
_Path = uri.Path.TrimStart(PATH_SEPARATORS).TrimEnd(PATH_SEPARATORS).Trim();
_ServerUrl = uri.Host;
_ServerUrl = _DnsName;
_Timeouts = TimeoutOptionsHelper.Parse(options);
var httpHandler = new HttpClientHandler();
+1 -1
View File
@@ -129,7 +129,7 @@ namespace Duplicati.Library.Main
?? new List<BackendEntry>();
var uri = new Library.Utility.Uri(backend);
var server = uri.Host;
var server = uri.Host ?? "";
var path = uri.Path;
var type = uri.Scheme;
var port = uri.Port;
+5 -5
View File
@@ -67,7 +67,7 @@ namespace Duplicati.Library.Utility
/// The server path, e.g. index.html.
/// Note that the path does NOT have a leading /.
/// </summary>
public readonly string? Path;
public readonly string Path;
/// <summary>
/// The server port, e.g. 80, is -1 if using the default port
/// </summary>
@@ -232,7 +232,7 @@ namespace Duplicati.Library.Utility
m_queryParams = null;
Scheme = scheme;
Host = host;
Path = path;
Path = path ?? "";
Query = query;
Username = username;
Password = password;
@@ -327,7 +327,7 @@ namespace Duplicati.Library.Utility
/// </summary>
/// <returns>A new instance</returns>
/// <param name="path">The new path to use</param>
public Uri SetPath(string path)
public Uri SetPath(string? path)
{
return new Uri(Scheme, Host, path, Query, Username, Password, Port);
}
@@ -337,7 +337,7 @@ namespace Duplicati.Library.Utility
/// </summary>
/// <returns>A new instance</returns>
/// <param name="query">The new query to use</param>
public Uri SetQuery(string query)
public Uri SetQuery(string? query)
{
return new Uri(Scheme, Host, Path, query, Username, Password, Port);
}
@@ -348,7 +348,7 @@ namespace Duplicati.Library.Utility
/// <returns>A new instance</returns>
/// <param name="username">The new username to use</param>
/// <param name="password">The new password to use</param>
public Uri SetCredentials(string username, string password)
public Uri SetCredentials(string? username, string? password)
{
return new Uri(Scheme, Host, Path, Query, username, password, Port);
}
+8 -8
View File
@@ -71,7 +71,7 @@ class Program
{
// Issue a signin token
var signinTokenResult = await client.IssueSigninTokenV1Async(
new IssueSigninTokenInputDto( Environment.GetEnvironmentVariable("TEST_PASSWORD") ) { }, CancellationToken.None);
new IssueSigninTokenInputDto(Environment.GetEnvironmentVariable("TEST_PASSWORD")!) { }, CancellationToken.None);
Console.WriteLine($"✓ Signin token issued: {signinTokenResult.Token[..10]}...");
// Issue a single operation token
@@ -85,7 +85,7 @@ class Program
var foreverToken = await client.IssueForeverTokenV1Async(CancellationToken.None);
Console.WriteLine($"✓ Forever token issued: {foreverToken.Token[..10]}...");
}
catch (Exception e)
catch (Exception)
{
// expected here if foreever tokens are disabled
}
@@ -137,7 +137,7 @@ class Program
// Export as command line
var cmdlineExport = await client.ExportCommandlineV1Async(backup.Backup.ID, CancellationToken.None);
Console.WriteLine($" ✓ Command line exported: {cmdlineExport.Command[..50]}...");
Console.WriteLine($" ✓ Command line exported: {cmdlineExport!.Command![..50]}...");
// Export arguments only
var argsExport = await client.ExportArgsOnlyV1Async(backup.Backup.ID, CancellationToken.None);
@@ -351,12 +351,12 @@ class Program
// Export backup configuration
var exportToken = await client.IssueTokenV1Async("export", CancellationToken.None);
var exportedConfig = await client.ExportBackupV1Async(firstBackup.Backup.ID,true, "random", exportToken.Token, CancellationToken.None);
var exportedConfig = await client.ExportBackupV1Async(firstBackup.Backup.ID, true, "random", exportToken.Token, CancellationToken.None);
Console.WriteLine($"✓ Exported backup configuration: {exportedConfig}");
// Export as command line
var cmdlineExport = await client.ExportCommandlineV1Async(firstBackup.Backup.ID, CancellationToken.None);
Console.WriteLine($"✓ Exported command line: {cmdlineExport.Command.Length} characters");
Console.WriteLine($"✓ Exported command line: {cmdlineExport!.Command![..50]}...");
// Export arguments only
var argsExport = await client.ExportArgsOnlyV1Async(firstBackup.Backup.ID, CancellationToken.None);
@@ -581,7 +581,7 @@ class Program
BackupId = firstBackup.Backup.ID
};
var filesetsResponse = await client.ListFilesetsV2Async(filesetsRequest, CancellationToken.None);
Console.WriteLine($"✓ V2 Filesets: {filesetsResponse.Data.ToArray().Length} items");
Console.WriteLine($"✓ V2 Filesets: {filesetsResponse!.Data!.ToArray().Length} items");
// List folder content with pagination
var folderRequest = new ListFolderContentRequestDto
@@ -593,7 +593,7 @@ class Program
Page = null
};
var folderResponse = await client.ListFolderContentV2Async(folderRequest, CancellationToken.None);
Console.WriteLine($"✓ V2 Folder Content: {folderResponse.Data.ToArray().Length} items,");
Console.WriteLine($"✓ V2 Folder Content: {folderResponse!.Data!.ToArray().Length} items,");
// Search entries
var searchRequest = new SearchEntriesRequestDto
@@ -606,7 +606,7 @@ class Program
Page = 0
};
var searchResponse = await client.SearchEntriesV2Async(searchRequest, CancellationToken.None);
Console.WriteLine($"✓ V2 Search Results: {searchResponse.Data.ToArray().Length} items");
Console.WriteLine($"✓ V2 Search Results: {searchResponse!.Data!.ToArray().Length} items");
// Test destination (commented out as it requires valid destination configuration)
/*