diff --git a/Duplicati/Library/Backend/Backblaze/B2.cs b/Duplicati/Library/Backend/Backblaze/B2.cs index ab705991b..bd37e351e 100644 --- a/Duplicati/Library/Backend/Backblaze/B2.cs +++ b/Duplicati/Library/Backend/Backblaze/B2.cs @@ -465,7 +465,7 @@ public class B2 : IStreamingBackend, ILockingBackend ).ConfigureAwait(false) ).ConfigureAwait(false); - if (response?.FileRetention?.RetainUntilTimestamp is long timestamp && timestamp > 0) + if (response?.FileRetention?.Value?.RetainUntilTimestamp is long timestamp && timestamp > 0) return Utility.Utility.EPOCH.AddMilliseconds(timestamp); return null; @@ -631,14 +631,14 @@ public class B2 : IStreamingBackend, ILockingBackend var fileId = await GetFileId(remotename, cancellationToken).ConfigureAwait(false); var config = await _b2AuthHelper.GetConfigAsync(cancellationToken).ConfigureAwait(false); - await Utility.Utility.WithTimeout(_timeouts.ShortTimeout, cancellationToken, async ct - => await _b2AuthHelper.PostAndGetJsonDataAsync( + var res = await Utility.Utility.WithTimeout(_timeouts.ShortTimeout, cancellationToken, async ct + => await _b2AuthHelper.PostAndGetJsonDataAsync( $"{config.APIUrl}/b2api/v2/b2_update_file_retention", new UpdateFileRetentionRequest { FileId = fileId, FileName = _prefix + remotename, - Retention = new FileRetention + FileRetention = new FileRetention { Mode = _lockMode.ToString().ToLower(), RetainUntilTimestamp = (long)(lockUntilUtc.ToUniversalTime() - Utility.Utility.EPOCH).TotalMilliseconds @@ -648,6 +648,9 @@ public class B2 : IStreamingBackend, ILockingBackend ct ).ConfigureAwait(false) ).ConfigureAwait(false); + + if (res.FileRetention?.RetainUntilTimestamp == null) + throw new Exception("Failed to set object lock, call succeeded but no retention info returned"); } /// diff --git a/Duplicati/Library/Backend/Backblaze/Model/FileRetention.cs b/Duplicati/Library/Backend/Backblaze/Model/FileRetention.cs index 02e14e5c3..6f357152a 100644 --- a/Duplicati/Library/Backend/Backblaze/Model/FileRetention.cs +++ b/Duplicati/Library/Backend/Backblaze/Model/FileRetention.cs @@ -32,6 +32,16 @@ internal class FileRetention public long? RetainUntilTimestamp { get; set; } } +internal class FileRetentionAccess +{ + [JsonProperty("isClientAuthorizedToRead")] + public bool isClientAuthorizedToRead { get; set; } + + [JsonProperty("value")] + public FileRetention? Value { get; set; } + +} + internal class GetFileInfoRequest { [JsonProperty("fileId")] @@ -39,11 +49,18 @@ internal class GetFileInfoRequest } internal class GetFileInfoResponse +{ + [JsonProperty("fileRetention")] + public FileRetentionAccess? FileRetention { get; set; } +} + +internal class UpdateFileRetentionResponse { [JsonProperty("fileRetention")] public FileRetention? FileRetention { get; set; } } + internal class UpdateFileRetentionRequest { [JsonProperty("fileId")] @@ -52,8 +69,8 @@ internal class UpdateFileRetentionRequest [JsonProperty("fileName")] public string? FileName { get; set; } - [JsonProperty("retention")] - public FileRetention? Retention { get; set; } + [JsonProperty("fileRetention")] + public FileRetention? FileRetention { get; set; } [JsonProperty("bypassGovernance")] public bool BypassGovernance { get; set; }