Files
duplicati/proprietary/GoogleWorkspace/SourceItems/CalendarEventSourceEntry.cs
T
Kenneth Skovhede 910c56b3c4 Reworked the use of scopes.
Instead of requesting all scopes up front, each sub-section of the backup/restore will request the permissions that are relevant for the operation.

The effect is that it is not required to grant all permissions to get a backup running. If permissions are failing, that part of the backup will generate warnings for items that are excluded.
2026-02-15 22:03:57 +01:00

44 lines
1.9 KiB
C#

// Copyright (c) 2026 Duplicati Inc. All rights reserved.
using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using Google.Apis.Calendar.v3.Data;
using System.Runtime.CompilerServices;
using Google.Apis.Drive.v3;
namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems;
internal class CalendarEventSourceEntry(string parentPath, Event evt, DriveService driveService)
: MetaEntryBase(Util.AppendDirSeparator(SystemIO.IO_OS.PathCombine(parentPath, evt.Id)), evt.CreatedDateTimeOffset.HasValue ? evt.CreatedDateTimeOffset.Value.UtcDateTime : DateTime.UnixEpoch, evt.UpdatedDateTimeOffset.HasValue ? evt.UpdatedDateTimeOffset.Value.UtcDateTime : DateTime.UnixEpoch)
{
public override async IAsyncEnumerable<ISourceProviderEntry> Enumerate([EnumeratorCancellation] CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested) yield break;
yield return new CalendarEventICSSourceEntry(this.Path, evt);
yield return new CalendarEventContentSourceEntry(this.Path, evt);
if (evt.Attachments != null)
{
foreach (var attachment in evt.Attachments)
{
if (cancellationToken.IsCancellationRequested) yield break;
yield return new CalendarEventAttachmentSourceEntry(this.Path, attachment, driveService);
}
}
}
public override Task<Dictionary<string, string?>> GetMinorMetadata(CancellationToken cancellationToken)
{
return Task.FromResult(new Dictionary<string, string?>
{
{ "gsuite:v", "1" },
{ "gsuite:Type", SourceItemType.CalendarEvent.ToString() },
{ "gsuite:Name", evt.Summary ?? evt.Id },
{ "gsuite:Id", evt.Id },
{ "gsuite:HtmlLink", evt.HtmlLink }
}
.Where(kv => !string.IsNullOrEmpty(kv.Value))
.ToDictionary(kv => kv.Key, kv => kv.Value));
}
}