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.
This commit is contained in:
Kenneth Skovhede
2026-02-15 22:03:57 +01:00
parent 3bc449281a
commit 910c56b3c4
53 changed files with 2954 additions and 366 deletions
@@ -2,22 +2,21 @@
using Duplicati.Library.Common.IO;
using File = Google.Apis.Drive.v3.Data.File;
using Google.Apis.Drive.v3;
namespace Duplicati.Proprietary.GoogleWorkspace.SourceItems;
internal class DriveFileContentSourceEntry(SourceProvider provider, string parentPath, File file)
internal class DriveFileContentSourceEntry(string parentPath, File file, DriveService driveService)
: StreamResourceEntryBase(SystemIO.IO_OS.PathCombine(parentPath, "content"), file.CreatedTimeDateTimeOffset.HasValue ? file.CreatedTimeDateTimeOffset.Value.UtcDateTime : DateTime.UnixEpoch, file.ModifiedTimeDateTimeOffset.HasValue ? file.ModifiedTimeDateTimeOffset.Value.UtcDateTime : DateTime.UnixEpoch)
{
public override long Size => file.Size ?? -1;
public override async Task<Stream> OpenRead(CancellationToken cancellationToken)
{
var service = provider.ApiHelper.GetDriveService();
if (GoogleMimeTypes.IsGoogleDoc(file.MimeType))
{
var exportMimeType = GoogleMimeTypes.GetExportMimeType(file.MimeType);
var request = service.Files.Export(file.Id, exportMimeType);
var request = driveService.Files.Export(file.Id, exportMimeType);
var stream = new MemoryStream();
await request.DownloadAsync(stream, cancellationToken);
stream.Seek(0, SeekOrigin.Begin);
@@ -25,7 +24,7 @@ internal class DriveFileContentSourceEntry(SourceProvider provider, string paren
}
else
{
var request = service.Files.Get(file.Id);
var request = driveService.Files.Get(file.Id);
var stream = new MemoryStream();
await request.DownloadAsync(stream, cancellationToken);
stream.Seek(0, SeekOrigin.Begin);